0

我在 HKEY_LOCAL_MACHINE SOFTWARE\Company\Company\ 中创建名为“Language”的 regedit 键,将在 Visual Studio 调试模式下创建,但我通过 Install shield 构建它,并将其安装在其他机器和操作系统(windows 7 窗口 8)中,密钥不能由应用程序创建。

在安装屏蔽步骤时,我创建了 SOFTWARE\Company\Company\ 的 Regedit 键,但我无法在此代码处更改语言的键

SetMainRegeditValue(theApp.mMainRegKey, theApp.mMainRegNormal[0], theApp.g_eLanguage);

这段代码会发生什么?

// In the global 
CRegKey mMainRegKey;
CString *mMainRegPath;
CString *mMainRegNormal;

....

theApp.mMainRegPath = new CString[1];
theApp.mMainRegPath[0] = _T("SOFTWARE\\Company\\Company\\");

theApp.mMainRegNormal = new CString[1];
theApp.mMainRegNormal[0] = _T("Language");

// Check Regedit value
if(theApp.mMainRegKey.Open(HKEY_LOCAL_MACHINE, theApp.mMainRegPath[0]) == ERROR_SUCCESS)
{
    TCHAR  tstrLan[_MAX_PATH];

    DWORD len = _MAX_PATH;
    DWORD lanlen = 8;
    if(theApp.mMainRegKey.QueryStringValue(_T("Version"),tstrLan, &lanlen) != ERROR_SUCCESS)
    {
        RegDeleteKey(HKEY_LOCAL_MACHINE, theApp.mMainRegPath[0]);
        RegDeleteKey(HKEY_LOCAL_MACHINE, theApp.mMainRegNormal[0]);

        SetMainRegeditValue(theApp.mMainRegKey,_T("Version"), _T("v2.0.0"));
    }
}

if(theApp.mMainRegKey.Open(HKEY_LOCAL_MACHINE,theApp.mMainRegPath[0]) != ERROR_SUCCESS)     
{
    theApp.mMainRegKey.Create(HKEY_LOCAL_MACHINE, theApp.mMainRegPath[0]);
    SetMainRegeditValue(theApp.mMainRegKey, theApp.mMainRegNormal[0], theApp.g_eLanguage);
}
4

1 回答 1

0

好的,我找到了规律。向HKEY_LOCAL_MACHINE写任何东西需要管理员权限,但HKEY_CURRENT_USER不是必须的,所以将HKEY_LOCAL_MACHINE替换为HKEY_CURRENT_USER,问题就解决了。

于 2014-01-13T03:44:33.970 回答