无法使用CRegKey打开HKEY_LOCAL_MACHINE \\ SOFTWARE密钥 [英] Unable to open HKEY_LOCAL_MACHINE\\SOFTWARE key with CRegKey

查看:409
本文介绍了无法使用CRegKey打开HKEY_LOCAL_MACHINE \\ SOFTWARE密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是检查密钥HKEY_LOCAL_MACHINE \\ SOFTWARE \\GITSourceControl


<下是否存在注册表值'email'和'username' p>如果它们不存在那么我想创建密钥GITSourceControl和值'email'和'username'。


但遗憾的是我甚至无法打开现有密钥'HKEY_LOCAL_MACHINE \\ SOFTWARE'并且我不知道为什么它不起作用。


我在下面做错了什么?

 CRegKey RegKey; 
if(RegKey.Open(HKEY_LOCAL_MACHINE," SOFTWARE\\GITSourceControl"))!= ERROR_SUCCESS)
{
RegKey.Close();
if(RegKey.Open(HKEY_LOCAL_MACHINE," \\Software")== ERROR_SUCCESS)
{
lResult = RegKey.Create(HKEY_LOCAL_MACHINE," GITSourceControl");
ASSERT(lResult == ERROR_SUCCESS);
RegKey.Close();
}
}
if(RegKey.Open(HKEY_LOCAL_MACHINE," SOFTWARE \\GITSourceControl")== ERROR_SUCCESS)
{
lResult = RegKey.SetStringValue ("电子邮件",strEmail);
ASSERT(lResult == ERROR_SUCCESS);
lResult = RegKey.SetStringValue(" Username",strUsername);
ASSERT(lResult == ERROR_SUCCESS);
}
其他
{
ASSERT(false);
}



解决方案

请参阅
CRegKey Class <的文档/ a>


默认情况下,CRegKey :: Open会请求写入权限。 除非您使用提升的权限运行,否则您没有对HKLM的写入权限。 使用提升权限运行代码以允许写访问。


代码还有其他需要调试的问题。 例如,

    if  < span class ="pln">    RegKey   打开   HKEY_LOCAL_MACHINE     " \\Software"      ==   ERROR_SUCCESS   

密钥的名称不应包含反斜杠。








All I want to do is check for the presence of the registry values 'email' and 'username' under the key HKEY_LOCAL_MACHINE\\SOFTWARE\\GITSourceControl

If they are not present then I want to create the key GITSourceControl and the values 'email' and 'username'.

But sadly I can't even open the existing key 'HKEY_LOCAL_MACHINE\\SOFTWARE' and I have no idea why it is not working.

What am I doing wrong below?

		CRegKey RegKey;
		if (RegKey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\GITSourceControl") != ERROR_SUCCESS)
		{
			RegKey.Close();
			if (RegKey.Open(HKEY_LOCAL_MACHINE, "\\Software") == ERROR_SUCCESS)
			{
				lResult = RegKey.Create(HKEY_LOCAL_MACHINE, "GITSourceControl");
				ASSERT(lResult == ERROR_SUCCESS);
				RegKey.Close();
			}
		}
		if (RegKey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\GITSourceControl") == ERROR_SUCCESS)
		{
			lResult = RegKey.SetStringValue("Email", strEmail);
			ASSERT(lResult == ERROR_SUCCESS);
			lResult = RegKey.SetStringValue("Username", strUsername);
			ASSERT(lResult == ERROR_SUCCESS);
		}
		else
		{
			ASSERT(false);
		}


解决方案

See the documentation at CRegKey Class

By default CRegKey::Open will request write access.  Unless you are running with elevated privileges you do not have write access to HKLM.  Run the code with elevated privilege to permit write access.

The code also has other problems that will need debugging.  For example,

	if (RegKey.Open(HKEY_LOCAL_MACHINE, "\\Software") == ERROR_SUCCESS)

The name of the key should not include the backslashes.





这篇关于无法使用CRegKey打开HKEY_LOCAL_MACHINE \\ SOFTWARE密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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