I create regedit key named "Language" in HKEY_LOCAL_MACHINE SOFTWARE\Company\Company\, in visual studio debug mode will be create, but I build it through Install shield, and Install it in other machine and OS (windows 7 window 8), the key can't create by application.
When step of Install shield, I create Regedit key of SOFTWARE\Company\Company\, But I can't Change the key of Language at this code
SetMainRegeditValue(theApp.mMainRegKey, theApp.mMainRegNormal[0], theApp.g_eLanguage);
what happen with this code ?
// 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);
}
OK, I find the rule. need administrator privileges to write anything to HKEY_LOCAL_MACHINE, but HKEY_CURRENT_USER not necessary, so replace HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER, the problem be solved.