# \[c#\] 보안모듈 자동 등록 코드 공유

**URL:** <https://forum.developer.hancom.com/t/c/782>\
**Category:** 한글 오토메이션\
**Created:** [7월 7, 2023, 2:08오전 UTC](https://forum.developer.hancom.com/t/c/782 "2023-07-07T02:08:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user63](https://avatars.discourse-cdn.com/v4/letter/u/49beb7/32.png) [@user63](https://forum.developer.hancom.com/u/user63)\
**Post date:** [7월 7, 2023, 2:08오전 UTC](https://forum.developer.hancom.com/t/c/782/1 "2023-07-07T02:08:07Z")

</div>

도움을 많이 받아서 혹시나 필요하신 분 계실까하여  
c#에서 자동으로 보안모듈 등록 여부 확인해서 레지스트리 등록 및 호출하는 코드를 공유합니다.  
해당 dll파일은 실행폴더안에 있다고 가정했습니다.  
다른 경로에 계시면 해당 경로만 변경하시면 됩니다.

//레지스트리에 보안모듈 추가  
RegistryKey key = Registry.CurrentUser.OpenSubKey(“SOFTWARE\HNC\HwpAutomation\Modules”, true);  
if (key == null)  
{  
key = Registry.CurrentUser.CreateSubKey(“SOFTWARE\HNC\HwpAutomation\Modules”);  
}  
if (key.GetValue(“FilePathCheckerModuleExample”) == null)  
{  
key.SetValue(“FilePathCheckerModuleExample”, Application.StartupPath + “\FilePathCheckerModuleExample.dll”);  
}

var ss = hwp.RegisterModule(“FilePathCheckDLL”, “FilePathCheckerModuleExample”);

---

<div class="post-metadata">

**Author:** ![cwy](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cwy](https://forum.developer.hancom.com/u/cwy)\
**Post date:** [7월 7, 2023, 2:29오전 UTC](https://forum.developer.hancom.com/t/c/782/2 "2023-07-07T02:29:58Z")

</div>

안녕하세요 한컴디벨로퍼입니다!  
코드 공유 감사합니다! 🙂 더 나은 포럼이 되기 위해 노력하겠습니다.

---

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [3월 7, 2024, 1:44오후 UTC](https://forum.developer.hancom.com/t/c/782/3 "2024-03-07T13:44:31Z")

</div>

감사합니다.  
파이썬으로는 잘 됐었는데 c#으로는 헤매이고 있었는데… 한방에 해결됐네요.  
다시 한번 감사합니다.

아 그리고 마지막 줄은

bool ss = hwp.RegisterModule(“FilePathCheckDLL”, “FilePathCheckerModuleExample”);  
if (ss) Debug.WriteLine(“보안모듈 승인 성공”);  
else Debug.WriteLine(“보안모듈 승인 실패”);

이렇게 하면 한번더 확인할 수 있겠네요

if (hwp.RegisterModule(“FilePathCheckDLL”, “FilePathCheckerModuleExample”))  
Debug.WriteLine(“보안모듈 승인 성공”);  
else Debug.WriteLine(“보안모듈 승인 실패”);

이렇게 바로 if문으로 확인해도 될테구요… (뒤에 다시 쓸 변수가 아닌듯 하여)

다시 한번 감사드립니다. ^^;
