ossentoo
asked on
Updating/Saving Registry Keys
I'm saving or modifying registry keys using 'RegOpenKeyEx' and
'RegSetValueEx'
Win32 functions.
- I can save String values to the registry e.g.:
[HKEY_LOCAL_MACHINE\System \CurrentCo ntrolSet\S ervices\Vx D\MSTCP]
"EnableDNS"="1"
"HostName"="joebloggs"
"Domain"=""
But I'm having problems with hex values e.g.:
[HKEY_LOCAL_MACHINE\System \CurrentCo ntrolSet\S ervices\Vx D\MSTCP\Se rviceProvi
der]
"LocalPriority"=hex:f3,01, 00,00
"HostsPriority"=hex:f4,01, 00,00
What type do I use in VC++ and how do I set it in hexadecimal freeform
(registry style).
- Alternatively I was thinking that there is an equivalent set of functions
in MFC??
Thanks a lot
OscarI'm saving or modifying registry keys using 'RegOpenKeyEx' and
'RegSetValueEx'
Win32 functions.
- I can save String values to the registry e.g.:
[HKEY_LOCAL_MACHINE\System \CurrentCo ntrolSet\S ervices\Vx D\MSTCP]
"EnableDNS"="1"
"HostName"="joebloggs"
"Domain"=""
But I'm having problems with hex values e.g.:
[HKEY_LOCAL_MACHINE\System \CurrentCo ntrolSet\S ervices\Vx D\MSTCP\Se rviceProvi
der]
"LocalPriority"=hex:f3,01, 00,00
"HostsPriority"=hex:f4,01, 00,00
What type do I use in VC++ and how do I set it in hexadecimal freeform
(registry style).
- Alternatively I was thinking that there is an equivalent set of functions
in MFC??
Thanks a lot
Oscar
'RegSetValueEx'
Win32 functions.
- I can save String values to the registry e.g.:
[HKEY_LOCAL_MACHINE\System
"EnableDNS"="1"
"HostName"="joebloggs"
"Domain"=""
But I'm having problems with hex values e.g.:
[HKEY_LOCAL_MACHINE\System
der]
"LocalPriority"=hex:f3,01,
"HostsPriority"=hex:f4,01,
What type do I use in VC++ and how do I set it in hexadecimal freeform
(registry style).
- Alternatively I was thinking that there is an equivalent set of functions
in MFC??
Thanks a lot
OscarI'm saving or modifying registry keys using 'RegOpenKeyEx' and
'RegSetValueEx'
Win32 functions.
- I can save String values to the registry e.g.:
[HKEY_LOCAL_MACHINE\System
"EnableDNS"="1"
"HostName"="joebloggs"
"Domain"=""
But I'm having problems with hex values e.g.:
[HKEY_LOCAL_MACHINE\System
der]
"LocalPriority"=hex:f3,01,
"HostsPriority"=hex:f4,01,
What type do I use in VC++ and how do I set it in hexadecimal freeform
(registry style).
- Alternatively I was thinking that there is an equivalent set of functions
in MFC??
Thanks a lot
Oscar
Can you post the relevant code? That way we can see if there's something wrong in your code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
void CMainDlg::OnOK()
{
// if our modeless child isn't already up, create it and display it
// otherwise, just set focus to it
CString strReg_SubKey[14];
CString strKeyData[14];
CEdit* pEdit;
LONG lSucess=0;
HKEY hValue; // handle of open key
CHAR *msg="\0";
CHAR ValueName[MAX_VALUE_NAME];
DWORD dwcValueName = MAX_VALUE_NAME;
DWORD dwType[14];
DWORD dwData[14];
CHAR *byData;
int i;
LPCSTR lpcData[14];
// Set up subkeys array
lpcData[0]="ComputerName\0 ";
lpcData[1]="EnableDNS\0";
lpcData[2]="HostName\0";
lpcData[3]="Domain\0";
lpcData[4]="SearchList\0";
lpcData[5]="NameServer\0";
lpcData[6]="MaxSockAddrLen gth\0";
lpcData[7]="MinSockAddrLen gth\0";
lpcData[8]="LocalPriority\ 0";
lpcData[9]="HostsPriority\ 0";
lpcData[10]="DnsPriority\0 ";
lpcData[11]="NetbtPriority \0";
lpcData[12]="Class\0";
lpcData[13]="ComputerName\ 0";
// Save key types array
dwType[0]=REG_SZ;
dwType[1]=REG_SZ;
dwType[2]=REG_SZ;
dwType[3]=REG_SZ;
dwType[4]=REG_SZ;
dwType[5]=REG_SZ;
dwType[6]=REG_BINARY;
dwType[7]=REG_BINARY;
dwType[8]=REG_BINARY;
dwType[9]=REG_BINARY;
dwType[10]=REG_BINARY;
dwType[11]=REG_BINARY;
dwType[12]=REG_BINARY;
dwType[13]=REG_SZ;
// lpcData[2]="ComputerName\0 ";
//Set up keys array
strReg_SubKey[0]="System\\ CurrentCon trolSet\\c ontrol\\Co mputerName \\Computer Name";
strReg_SubKey[1]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP" ;
strReg_SubKey[2]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP" ;
strReg_SubKey[3]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP" ;
strReg_SubKey[4]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP" ;
strReg_SubKey[5]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP" ;
strReg_SubKey[6]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP\ \Parameter s\\Winsock ";
strReg_SubKey[7]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP\ \Parameter s\\Winsock ";
strReg_SubKey[8]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP\ \ServicePr ovider";
strReg_SubKey[9]="System\\ CurrentCon trolSet\\S ervices\\V xD\\MSTCP\ \ServicePr ovider";
strReg_SubKey[10]="System\ \CurrentCo ntrolSet\\ Services\\ VxD\\MSTCP \\ServiceP rovider";
strReg_SubKey[11]="System\ \CurrentCo ntrolSet\\ Services\\ VxD\\MSTCP \\ServiceP rovider";
strReg_SubKey[12]="System\ \CurrentCo ntrolSet\\ Services\\ VxD\\MSTCP \\ServiceP rovider";
strReg_SubKey[13]="System\ \CurrentCo ntrolSet\\ Services\\ VxD\\VNETS UP";
//regkey data
dwData[6]=268435456;
dwData[7]=268435456;
dwData[8]=268435456;
dwData[9]=268435456;
dwData[10]=268435456;
dwData[11]=268435456;
dwData[12]=268435456;
// check we have allocated correctly on memory heap
pEdit = (CEdit*) GetDlgItem(IDC_HOSTNAME);
ASSERT(pEdit != NULL);
if (pEdit != NULL)
pEdit->GetWindowText(strKe yData[0]);
byData=new CHAR [strKeyData->GetLength()+1 ];
//Registry key data to set
strKeyData[1]="1";
strKeyData[2]=strKeyData[0 ];
strKeyData[3]="";
strKeyData[4]="europe.ra.r ockwell.co m,bel.ra.r ockwell.co m,mke.ra.r ockwell.co m";
strKeyData[5]="199.33.71.3 4,205.175. 200.11,130 .151.82.12 1";
strKeyData[13]=strKeyData[ 0];
for (i=6;i<NUM_REG_KEYS;i++)
{
lSucess=RegOpenKeyEx(HKEY_ LOCAL_MACH INE, (LPCTSTR)strReg_SubKey[i], 0,KEY_QUER Y_VALUE,&h Value);
if (lSucess!=ERROR_SUCCESS)
{
// Message box the error
strcpy(msg,(LPCSTR)strReg_ SubKey[i]) ;
strcat(msg,": Replace failed!!");
AfxMessageBox(msg);
}
else
{
switch(dwType[i])
{
case REG_BINARY:
// Replace the registry string
lSucess=RegSetValueEx(hVal ue,lpcData [i],0,dwTy pe[i],
(BYTE*)&dwData[i],sizeof(d wData[i])) ;
break;
case REG_SZ:
// Replace the registry string
strcpy(byData, (LPCSTR)strKeyData[i]);
strcpy(ValueName,lpcData[i ]);
lSucess=RegSetValueEx(hVal ue,ValueNa me,0,dwTyp e[i],
(BYTE*)byData,strKeyData[i ].GetLengt h()+1);
break;
default:
AfxMessageBox("Didn't evaluate switch");
}
RegCloseKey(hValue);
}
}
delete byData;
AfxMessageBox ("Finished changing keys.", MB_OK);
EndDialog(0);
}
{
// if our modeless child isn't already up, create it and display it
// otherwise, just set focus to it
CString strReg_SubKey[14];
CString strKeyData[14];
CEdit* pEdit;
LONG lSucess=0;
HKEY hValue; // handle of open key
CHAR *msg="\0";
CHAR ValueName[MAX_VALUE_NAME];
DWORD dwcValueName = MAX_VALUE_NAME;
DWORD dwType[14];
DWORD dwData[14];
CHAR *byData;
int i;
LPCSTR lpcData[14];
// Set up subkeys array
lpcData[0]="ComputerName\0
lpcData[1]="EnableDNS\0";
lpcData[2]="HostName\0";
lpcData[3]="Domain\0";
lpcData[4]="SearchList\0";
lpcData[5]="NameServer\0";
lpcData[6]="MaxSockAddrLen
lpcData[7]="MinSockAddrLen
lpcData[8]="LocalPriority\
lpcData[9]="HostsPriority\
lpcData[10]="DnsPriority\0
lpcData[11]="NetbtPriority
lpcData[12]="Class\0";
lpcData[13]="ComputerName\
// Save key types array
dwType[0]=REG_SZ;
dwType[1]=REG_SZ;
dwType[2]=REG_SZ;
dwType[3]=REG_SZ;
dwType[4]=REG_SZ;
dwType[5]=REG_SZ;
dwType[6]=REG_BINARY;
dwType[7]=REG_BINARY;
dwType[8]=REG_BINARY;
dwType[9]=REG_BINARY;
dwType[10]=REG_BINARY;
dwType[11]=REG_BINARY;
dwType[12]=REG_BINARY;
dwType[13]=REG_SZ;
// lpcData[2]="ComputerName\0
//Set up keys array
strReg_SubKey[0]="System\\
strReg_SubKey[1]="System\\
strReg_SubKey[2]="System\\
strReg_SubKey[3]="System\\
strReg_SubKey[4]="System\\
strReg_SubKey[5]="System\\
strReg_SubKey[6]="System\\
strReg_SubKey[7]="System\\
strReg_SubKey[8]="System\\
strReg_SubKey[9]="System\\
strReg_SubKey[10]="System\
strReg_SubKey[11]="System\
strReg_SubKey[12]="System\
strReg_SubKey[13]="System\
//regkey data
dwData[6]=268435456;
dwData[7]=268435456;
dwData[8]=268435456;
dwData[9]=268435456;
dwData[10]=268435456;
dwData[11]=268435456;
dwData[12]=268435456;
// check we have allocated correctly on memory heap
pEdit = (CEdit*) GetDlgItem(IDC_HOSTNAME);
ASSERT(pEdit != NULL);
if (pEdit != NULL)
pEdit->GetWindowText(strKe
byData=new CHAR [strKeyData->GetLength()+1
//Registry key data to set
strKeyData[1]="1";
strKeyData[2]=strKeyData[0
strKeyData[3]="";
strKeyData[4]="europe.ra.r
strKeyData[5]="199.33.71.3
strKeyData[13]=strKeyData[
for (i=6;i<NUM_REG_KEYS;i++)
{
lSucess=RegOpenKeyEx(HKEY_
if (lSucess!=ERROR_SUCCESS)
{
// Message box the error
strcpy(msg,(LPCSTR)strReg_
strcat(msg,": Replace failed!!");
AfxMessageBox(msg);
}
else
{
switch(dwType[i])
{
case REG_BINARY:
// Replace the registry string
lSucess=RegSetValueEx(hVal
(BYTE*)&dwData[i],sizeof(d
break;
case REG_SZ:
// Replace the registry string
strcpy(byData, (LPCSTR)strKeyData[i]);
strcpy(ValueName,lpcData[i
lSucess=RegSetValueEx(hVal
(BYTE*)byData,strKeyData[i
break;
default:
AfxMessageBox("Didn't evaluate switch");
}
RegCloseKey(hValue);
}
}
delete byData;
AfxMessageBox ("Finished changing keys.", MB_OK);
EndDialog(0);
}
ASKER
How exactly do you set a type REG_BINARY,
IS IT 0x000000f5 for example??
IS IT 0x000000f5 for example??