Problem with the registry
-
The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart
-
The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart
-
The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart
You have to create RegKey using options 'REG_OPTION_NON_VOLATILE' instead of 'REG_OPTION_VOLATILE'. For more details, Check RegCreateKeyEx API in MSDN. If you are developing MFC/ATL based app...you can use CRegKey for easy registry access. Hope this helps. Ramu
-
The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart
this way is how I do it:
HKEY hKey;
int iLength = 0;
CString csPathSubClau = "";iLength = csNouValor.GetLength();
// Obrir la clau requerida.
csPathSubClau.Format("%s\\%s",m_csPathBase,csSubClau);RegOpenKeyEx(HKEY_LOCAL_MACHINE,csPathSubClau,0,KEY_ALL_ACCESS,&hKey);
RegSetValueEx(hKey,csValor,0,REG_SZ,(BYTE *)csNouValor.GetBuffer(iLength),iLength);RegFlushKey(hKey);
RegCloseKey(hKey); -
You have to create RegKey using options 'REG_OPTION_NON_VOLATILE' instead of 'REG_OPTION_VOLATILE'. For more details, Check RegCreateKeyEx API in MSDN. If you are developing MFC/ATL based app...you can use CRegKey for easy registry access. Hope this helps. Ramu
-
The problem is that all data that i save in the registry is gone after windows (2000) is restarted. All data appears to be ok after the application closes. But after the restart the key is completely gone. The code used in the app: Opening the key: HKEY hKeyRoot = HKEY_CURRENT_USER; LPCTSTR pszPath = "Software\\Companyname\\My App Name\\Settings" HKEY hKey; DWORD dw; RegCreateKeyEx(hKeyRoot, pszPath, 0L, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw); Writing: int iValue = 8; LPCTSTR pszKey = "MyInteger"; hKey as returned by RegCreateKeyEx RegSetValueEx(hKey, pszKey, 0L, REG_DWORD, (CONST BYTE*)&iValue, sizeof(int)); Does anyone know how to prevent this and why it happens? Thanks I'm smart enough to know that i'm stupid and i'm stupid enough to think that i'm smart
Never use KEY_ALL_ACCESS - only request the access you need. Only admininstrators can open keys with KEY_ALL_ACCESS. --Mike-- I'm bored... Episode I bored. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm