Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool CodeProjectUtils::UpdateRegistry(CString strNetCfgInstanceId, LPCTSTR lpszMacID /*= NULL*/)
- {
- bool bRet = false;
- HKEY hKey = NULL;
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}"),
- 0,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS)
- {
- DWORD dwIndex = 0;
- TCHAR Name[1024];
- DWORD cName = 1024;
- while( RegEnumKeyEx(hKey, dwIndex, Name, &cName,
- NULL, NULL, NULL, NULL) == ERROR_SUCCESS )
- {
- HKEY hSubKey = NULL;
- if(RegOpenKeyEx(hKey,Name,0,KEY_ALL_ACCESS,&hSubKey) == ERROR_SUCCESS)
- {
- BYTE Data[1204];
- DWORD cbData = 1024;
- if(RegQueryValueEx(hSubKey,_T("NetCfgInstanceId"),NULL,NULL,Data,&cbData) == ERROR_SUCCESS)
- {
- if(_tcscmp((TCHAR*)Data,strNetCfgInstanceId) == 0)
- {
- if(lpszMacID == NULL)
- {
- //Delete the NetCfgInstanceId entry
- LONG nErr = RegDeleteValue(hSubKey, _T("NetworkAddress"));
- if( (nErr == ERROR_SUCCESS) || (nErr == ERROR_FILE_NOT_FOUND) )
- {
- bRet = true;
- }
- }
- else
- {
- //Add the NetCfgInstanceId entry
- if(RegSetValueEx(hSubKey,_T("NetworkAddress"),0,REG_SZ,(const BYTE*)lpszMacID,sizeof(TCHAR) * ((DWORD)_tcslen(lpszMacID) + 1)) == ERROR_SUCCESS)
- {
- bRet = true;
- }
- }
- }
- }
- RegCloseKey(hSubKey);
- }
- cName = 1024;
- dwIndex++;
- }
- RegCloseKey(hKey);
- }
- return bRet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement