how shall i create a key in registry
-
hello all, how shall i create a entry in registry using VC++. i mean i need to add a key such that my application name shouldnt appear there. i mean there is an entry named "Extensions" in the registry and i need to create an entry {"Demo App"} in that. and then i need to add entries in the newly created. but the problem with SetRegistryKey() is that it is creating the application name too. but i dont need it. how shall i do so. ComputerNewton
-
hello all, how shall i create a entry in registry using VC++. i mean i need to add a key such that my application name shouldnt appear there. i mean there is an entry named "Extensions" in the registry and i need to create an entry {"Demo App"} in that. and then i need to add entries in the newly created. but the problem with SetRegistryKey() is that it is creating the application name too. but i dont need it. how shall i do so. ComputerNewton
int RegWriteKeyValue(HKEY hKeyParent,CString strPath,CString strKey,CString strVal) { CRegKey regKey; DWORD dwKeyCreateMode=REG_OPENED_EXISTING_KEY; long lRes; lRes=regKey.Create(hKeyParent,strPath,REG_NONE,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&dwKeyCreateMode); if (lRes != ERROR_SUCCESS) return 0; lRes=regKey.SetValue(strVal,strKey); if (lRes != ERROR_SUCCESS) return 0; // close the registry key regKey.Close(); return 1; } RegWriteKeyValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce","Name","value");
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
int RegWriteKeyValue(HKEY hKeyParent,CString strPath,CString strKey,CString strVal) { CRegKey regKey; DWORD dwKeyCreateMode=REG_OPENED_EXISTING_KEY; long lRes; lRes=regKey.Create(hKeyParent,strPath,REG_NONE,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&dwKeyCreateMode); if (lRes != ERROR_SUCCESS) return 0; lRes=regKey.SetValue(strVal,strKey); if (lRes != ERROR_SUCCESS) return 0; // close the registry key regKey.Close(); return 1; } RegWriteKeyValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce","Name","value");
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
Thank u very much for ur help. But it is in ATL. i dont want to use this in ATL. once again thanks a lot. b'coz of ur reply i got an idea and i did it in SDK mixed with MFC to get my requirement. Once again thank u very much. ComputerNewton
-
Thank u very much for ur help. But it is in ATL. i dont want to use this in ATL. once again thanks a lot. b'coz of ur reply i got an idea and i did it in SDK mixed with MFC to get my requirement. Once again thank u very much. ComputerNewton
use CRegKey of ATL classes.
God is Real, unless declared Integer.
-
hello all, how shall i create a entry in registry using VC++. i mean i need to add a key such that my application name shouldnt appear there. i mean there is an entry named "Extensions" in the registry and i need to create an entry {"Demo App"} in that. and then i need to add entries in the newly created. but the problem with SetRegistryKey() is that it is creating the application name too. but i dont need it. how shall i do so. ComputerNewton
Use the Win32 registry functions. Ugly, yes, but they work:
// First create the key. HKEY hNewKey = NULL; DWORD disposition = 0; DWORD error = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Extensions\\Demo App", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewKey, &disposition); // Now create the value char myString[] = "Some Data"; error = ::RegSetValueEx(hNewKey, "Some Value", NULL, REG_SZ, myString, sizeof(myString));
See MSDN on RegCreateKeyEx and RegSetValueEx for more info. (The code I provided is just a rough example... should compile and work but I can't be sure!) Sometimes I feel like I'm a USB printer in a parallel universe.