在Windows Vista上编程注册.dll(使用DllRegisterServer) [英] Programatically registering .dll's on Windows Vista (using DllRegisterServer)

查看:288
本文介绍了在Windows Vista上编程注册.dll(使用DllRegisterServer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是调用 regsvr32.exe ,可以使用以下步骤注册一个.DLL:

  HINSTANCE hLib = :: LoadLibraryEx(dllPath,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); 
HRESULT(STDAPICALLTYPE * lpDllEntryPoint)(void);
(FARPROC&)lpDllEntryPoint = :: GetProcAddress(hLib,DllRegisterServer);
const HRESULT hRes =(* lpDllEntryPoint)();

这在Windows XP上工作正常。遗憾的是,它在Vista上失败,但只有一些特定的DLL。 hRes 成为 E_ACCESSDENIED 。我想这是一个安全问题。有没有人知道如何从Windows Vista的代码注册一个.DLL?



注意:我以管理员身份登录时运行此代码。

解决方案

COM注册需要写入对 HKEY_LOCAL_MACHINE 部分注册表的访问



在UAC下,写入 HKEY_LOCAL_MACHINE 的访问需要一个升级的管理员。 / p>

获取升级过程的最简单方法是使用指定requireAdministrator访问的清单来创建它。 - 在项目属性 - >配置属性 - >链接器 - >清单文件 - > UAC执行级别下方设置正确的设置。



这意味着你可能想要将您的EXE分成两部分。 正常asInvoker部分,并且当检测到自我注册时,需要升高InstallMyself部分。当非升高部分检测到第一次运行的类型条件时,需要使用ShellExecute(Ex)来执行FirstInstall.exe部分 - 使用CreateProcess或其他一些API将会失败并且不具有特权错误。 ShellExecute将显示UAC提示。



可以使用应用程序隔离加载COM dll而没有任何注册步骤。






不幸的是,原因无法确定。但是,如果您有兴趣进行进一步的研究,那么将帮助很多的工具将是来自 SysInternals 。过程监视器可以记录一个进程的文件,注册表和其他访问权限,包括所有成功和失败代码,使其更容易调试这样的问题,而无需使用更深层次的逆向工程。


Instead of calling regsvr32.exe, one can register a .DLL using the following steps:

HINSTANCE hLib = ::LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
HRESULT (STDAPICALLTYPE* lpDllEntryPoint)(void);
(FARPROC&)lpDllEntryPoint = ::GetProcAddress(hLib, "DllRegisterServer");
const HRESULT hRes = (*lpDllEntryPoint)();

This works fine on Windows XP. Regrettably, it fails on Vista, but only with some specific DLLs. hRes becomes E_ACCESSDENIED. I guess this is a security issue. Does anyone know how to register a .DLL from code on Windows Vista?

Note: I was logged in as administrator when running this code.

解决方案

COM registration requires write access to the HKEY_LOCAL_MACHINE part of the registry.

Under UAC, write access to the HKEY_LOCAL_MACHINE requires an elevated administrator.

The easiest way to get an elevated process is to create it with a manifest that specifies 'requireAdministrator' access. - Look under the Project Properties -> Configuration Properties->Linker->Manifest File->UAC Execution Level to set the correct setting.

This means you will probably want to split your EXE into two parts. The 'normal' asInvoker part, and, when self registration is detected as a requirement, an elevated InstallMyself part. When the non elevated part detects a first-run type condition, it needs to use ShellExecute(Ex) to execute the FirstInstall.exe part - using CreateProcess or some other API will simply fail with a insufficient privilege error. ShellExecute will present the UAC prompt.

It is possible to use Application Isolation to load COM dll's without any registration step at all.


Is is unfortunate that the cause cannot be determined. However, if you are interested in doing further research, a tool that will help a lot would be Process Monitor from SysInternals. Process Monitor can log all the File, Registry and other access for a process, including all success and fail codes making it a lot easier to debug problems like this without having to resort to deeper means of reverse engineering.

这篇关于在Windows Vista上编程注册.dll(使用DllRegisterServer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆