在尝试升级某些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编写的。
感谢您的期待。
答案 0 :(得分:3)
自Vista以来,对注册表某些区域的访问已被锁定。用户必须具有“提升”权限。尝试使用“以管理员身份运行”运行程序(在资源管理器中右键单击它)。
答案 1 :(得分:1)
见Registry Key Security and Access Rights和
RegCreateKeyEx
对于参数“hKey [in]打开注册表项的句柄。调用进程必须具有KEY_CREATE_SUB_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)