Is there a .NET or Win32 version of regsvr32?

吃可爱长大的小学妹 提交于 2019-12-02 09:49:45

问题


Is there a .NET or Win32 version of regsvr32? I would like to register a COM DLL with code instead of shelling out to the regsvr32 program.


回答1:


The standard way of registering an assembly is to call the exported DllRegisterServer function on the assembly.

  • http://msdn.microsoft.com/en-us/library/ms682162(v=VS.85).aspx

In simplified terms regsvr32 essentially does the following (error checking omitted for brevity).

HANDLE lib = LoadLibrary(...);
FARPROC proc = GetProcAddress(lib, "DllRegisterServer");
proc();



回答2:


Yes, it simply requires calling the exported function. The devil is in the details though. The DLL will load all its implicitly linked dependent DLLs as well. And their DllMain() entrypoints will run. That's kinda okay in a simple process like regsvr32, not so okay in yours that needs to survive beyond the registration step.

Then there's getting the permissions to write to the registry. UAC will definitely put a stop to that, both for running Regsvr32 as well as calling the entrypoint directly. To get permission from the user you will need a separate EXE with a manifest that asks for admin rights. You're not ahead.

Look into reg-free COM, supplying the registration info in a manifest. You then won't have to register the DLL anymore. You'll get lots of hits if you search for the term.




回答3:


I believe you just load the DLL, then call it exported DllRegisterServer() function.



来源:https://stackoverflow.com/questions/3559305/is-there-a-net-or-win32-version-of-regsvr32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!