在尝试升级某些C软件以在Windows 7中运行时,我遇到了一些从头开始创建注册表项的问题 .
这是我的代码:
//
// Create a brand new registry key
//
LONG Registry::CreateRegister( std::string path )
{
HKEY hKey;
DWORD dwDisposition;
LONG openRes = RegCreateKeyEx( HKEY_CLASSES_ROOT,
path.c_str(),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition );
RegCloseKey( hKey );
return openRes;
}
在Windows XP中,RegCreateKeyEx函数成功创建了注册表项,返回success(0)值 . 在Windows 7中,我从同一个函数获得返回值5(拒绝访问) .
我使用了regedit工具来确保我的帐户具有必要的完整权限,但没有成功 . 任何人都可以看到我可能出错的地方,或者在Windows 7中使用Visual Studio时是否还有其他陷阱和已知问题需要注意?
该软件目前是用Visual Studio 2003编写的 .
谢谢你的期待 .
2 回答
自Vista以来,访问注册表的某些区域已被锁定 . 用户必须具有“提升”权限 . 尝试使用“以管理员身份运行”运行程序(在资源管理器中右键单击它) .
见Registry Key Security and Access Rights和RegCreateKeyEx
对于参数"hKey [in] A handle to an open registry key. The calling process must have KEY_CREATE_SUB_KEY access to the key."
这个tuto帮你Teach Your Apps To Play Nicely With Windows Vista User Account Control
和The Windows Vista and Windows Server 2008 Developer Story: Windows Vista Application Development Requirements for User Account Control (UAC)