|
|
Comments and Discussions
|
|
 |

|
Is there any license limitation ?
|
|
|
|

|
Dear Robert, first thank's very much for share your code, nice Job,
I start to use it, and I need another functionaly, navigate trough subkeys, I add this fuctionaly to your class and I thing it's a good function to include in the article,
BOOL CRegistry::QuerySubKey(int index, CString& subkeyname)
{
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
DWORD i, retCode;
HKEY hKey;
ASSERT(m_strCurrentPath.GetLength() > 0);
if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0,
KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return FALSE;
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
// Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time
// Enumerate the subkeys, until RegEnumKeyEx fails.
if (cSubKeys)
{
if ((index < 0) || (index >= cSubKeys))
return FALSE;
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, index,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
{
subkeyname = achKey;
}
else
return FALSE;
}
::RegCloseKey(hKey);
return TRUE;
}
And a little example of how to use it:
m_reg.SetRootKey(HKEY_LOCAL_MACHINE);
if (m_reg.SetKey("Software\\NFFormDestiller\\ExportDrivers", FALSE)) {
for (int x = 0; x < m_reg.GetSubKeyCount(); x++) {
CString subkey;
if (m_reg.QuerySubKey(x, subkey)) {
CRegistry reg;
reg.SetRootKey(HKEY_LOCAL_MACHINE);
if (reg.SetKey("Software\\NFFormDestiller\\ExportDrivers\\"+subkey, FALSE)) {
CString desc = reg.ReadString("","");
int index = m_lstcfg.InsertItem(x,desc,0);
m_lstcfg.SetItemText(index,1,subkey);
}
}
}
}
Best Regards
Rey
|
|
|
|

|
i cant believe noone has relied to this... vider, thank you so much for this addon (i couldnt use this class for what i wanted without it)! and of course, thank your Robert for the class/code. Excellent stuff.im coming from a C# background (im young, i know!), and code like this is making me realize how usable MFC can be, to the point where now i prefer it.
just wanted to again say thanks!
-daniel b
|
|
|
|

|
I tried to write Systems IP address into registry. When UNICODE is not defined then i could see the value from registry. And if Unicode is defined then i'm seeing 4 square boxed in the place of IP address..
How to show the IP address in the registry though UNICODE is defined?
Code snippet:
int main(void)
{
HKEY hKey;
char name[] = "199.68.56.33";
RegOpenKeyExW(HKEY_LOCAL_MACHINE,L"SOFTWARE\\MyCompany\\\\InstallInfo", 0, KEY_ALL_ACCESS, &hKey);
RegSetValueEx(hKey, L"FTEBaseIPAddress", 0, REG_SZ, name, ((strlen(name)+1)*sizeof(TCHAR)) );
return 1;
}
ssssssssssssssssssssssss
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
|
|
|
|

|
I'm sorry about my poor english, but u shoud use _T("") rathor than L""
|
|
|
|

|
when enumerating the registry or passing across buffers is there a need to null terminate the buffer as shown below:
DWORD dwSize = MAX_PATH;
TCHAR szSubkeyName[MAX_PATH+1];
memset(szSubkeyName,0x00,sizeof(TCHAR)*(MAX_PATH+1));
while( RegEnumKeyEx(hKey,
dwIndex,
szSubkeyName,
&dwSize,
NULL,
NULL,
NULL,
&ftLastWriteTime) == ERROR_SUCCESS)
{
|
|
|
|

|
Hi Robert,
I hope you don't mind (and you are mentioned in it), but I took your excellent format of this class (CRegistry) and created a class that uses the nt.dll Native functions (e.g. NtCreateKey, NtDeleteKey, etc...). I did this because I have enjoyed you class for a long time and always use in apps that I write. I especially like the simplicity of it and that is why I adopted it for this new class I wrote "CNtRegistry" - link is below. Please take a look and let me know what you think?
There is a lot of added stuff in it like "Hiding Keys, Copying Keys/Values, Searching, Deleting recursively, etc...". I did this because I saw a lot of folks here asking for it.
http://www.codeproject.com/system/NtRegistry.asp[^]
Again, let me know what you think.
Regards,
Dan
|
|
|
|

|
I am trying to read a key of the type Binary, I do not see any function for this, The data is actually a person's name so I need to read a type Binary into a CSrting
Example: 44 00 6F 00 6E 00 20 00 4C 00 61 00 76 00 65 00 72 00 64 00 75 00 72 00 65
Converted=Don Laverdure
Any suggestions?
Cheers,
Don
|
|
|
|
|

|
Thanks for a useful class. It would be nice if WriteDword() specified REG_DWORD instead of REG_BINARY.
Jason
The question of whether computers can think is like the question of whether submarines can swim (Dijkstra)
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A simple registry class
| Type | Article |
| Licence | |
| First Posted | 17 Nov 1999 |
| Views | 179,207 |
| Bookmarked | 65 times |
|
|