Read / Write Registry
-
Hiya, Please halp me! I need some code to read & write registry keys in a particular place that already exists: "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" above is the location and then i need to write a new key & read a key. DWord and Edit. Is there a simple way to do this? Thank you for your time. :) An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
-
There is CRegKey class in the VC++ 6.0 installation somewhere, it is easy to use.
I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
-
Hiya, Please halp me! I need some code to read & write registry keys in a particular place that already exists: "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" above is the location and then i need to write a new key & read a key. DWord and Edit. Is there a simple way to do this? Thank you for your time. :) An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
There is CRegKey class in the VC++ 6.0 installation somewhere, it is easy to use.
-
I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
This is declaration of that class: class CRegKey { public: CRegKey(); ~CRegKey(); // Attributes public: operator HKEY() const; HKEY m_hKey; // Operations public: LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName); LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName); LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL); LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL); LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS); LONG Close(); HKEY Detach(); void Attach(HKEY hKey); LONG DeleteSubKey(LPCTSTR lpszSubKey); LONG RecurseDeleteKey(LPCTSTR lpszKey); LONG DeleteValue(LPCTSTR lpszValue); }; and you can do this: CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings"); and then reg.QueryValue(...); //to read value reg.SetValue(...) //to write value
-
Lucky the code machine wrote: Date:13:17 29 May '02 You had posted your answer to my message two minutes before I posted it. :confused:
Nice! Im in England so i guess something to do with that? :confused: Thanks a lot for that on registrys, i will try that. Looks good. Thanks An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
-
I dont understand (Sory) How do i get at / read that? An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
Lucky the code machine wrote: Date:13:17 29 May '02 You had posted your answer to my message two minutes before I posted it. :confused:
-
This is declaration of that class: class CRegKey { public: CRegKey(); ~CRegKey(); // Attributes public: operator HKEY() const; HKEY m_hKey; // Operations public: LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName); LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName); LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount); LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL); LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL); LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS); LONG Close(); HKEY Detach(); void Attach(HKEY hKey); LONG DeleteSubKey(LPCTSTR lpszSubKey); LONG RecurseDeleteKey(LPCTSTR lpszKey); LONG DeleteValue(LPCTSTR lpszValue); }; and you can do this: CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings"); and then reg.QueryValue(...); //to read value reg.SetValue(...) //to write value
I hope im not being a pain. I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky