需要修改一个数据库默认存储路径的地址,所以写了几个个修改注册表的函数主要就是用到了RegOpenKeyEx()和RegQueryValueEx()还有RegSetValueEx()
其实就是用RegOpenKeyEx()打开注册表 操作了一下而已...
1,查询用户数据库数据默认存储路径
1 void QueryData()
2 {
3 // TODO: Add your control notification handler code here
4 HKEY hKey;
5 LPCTSTR data_Set="Software\\Microsoft\\Microsoft SQL Server\\MSSQL10.MSSQL\\MSSQLServer";
6 long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_READ,&hKey));
7 if(ret0!=ERROR_SUCCESS){
8 MessageBox("无法打开文件");
9 return ;
10 }
11
12 LPBYTE DefaultData_Get=new BYTE[80];
13 DWORD type1=REG_SZ;
14 DWORD cbData1=80;
15
16 long ret1=::RegQueryValueEx(hKey,"DefaultData",NULL,&type1,DefaultData_Get,&cbData1);
17 if(ret1!=ERROR_SUCCESS){
18 MessageBox("无法打开文件");
19 return;
20 }
21
22 CString str_DefaultData=DefaultData_Get;
23 delete [] DefaultData_Get;
24
25 MessageBox(str_DefaultData);
26
27 ::RegCloseKey(hKey);
28
29 }
2,修改用户数据库数据默认存储路径为UPDATEDATA
1 #define UPDATEDATA "F:\\test"
void UpDateDataR()
2 {
3 // TODO: Add your control notification handler code here
4 HKEY hKey;
5 LPCTSTR data_Set="Software\\Microsoft\\Microsoft SQL Server\\MSSQL10.MSSQL\\MSSQLServer";
6 long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_WRITE,&hKey));
7 if(ret0!=ERROR_SUCCESS){
8 MessageBox("无法打开文件");
9 return ;
10 }
11
12 CString DataStr=UPDATEDATA ;
13 LPBYTE lpctDataStr=CString_To_LPBYTE(DataStr);
14
15 DWORD type1=REG_SZ;
16 DWORD cbData1=DataStr.GetLength()+1;
17
18 long ret1=::RegSetValueEx(hKey, "DefaultData", NULL,
19 type1, lpctDataStr, cbData1);
20 if(ret1!=ERROR_SUCCESS)
21 {
22 MessageBox("错误: 无法修改有关注册表信息!");
23 return;
24 }
25
26 ::RegCloseKey(hKey);
27 MessageBox("修改成功");
28
29
30
31
32 }
3查询用户数据库日志log默认存储路径
1 void Querylog()
2 {
3 // TODO: Add your control notification handler code hereHKEY hKey;
4 HKEY hKey;
5 LPCTSTR log_Set="Software\\Microsoft\\Microsoft SQL Server\\MSSQL10.MSSQL\\MSSQLServer";
6 long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,log_Set,0,KEY_READ,&hKey));
7 if(ret0!=ERROR_SUCCESS){
8 MessageBox("无法打开文件");
9 return ;
10 }
11
12 LPBYTE Defaultlog_Get=new BYTE[80];
13 DWORD type1=REG_SZ;
14 DWORD cbData1=80;
15
16 long ret1=::RegQueryValueEx(hKey,"Defaultlog",NULL,&type1,Defaultlog_Get,&cbData1);
17 if(ret1!=ERROR_SUCCESS){
18 MessageBox("无法打开文件");
19 return;
20 }
21
22 CString str_DefaultData=Defaultlog_Get;
23 delete [] Defaultlog_Get;
24
25 MessageBox(str_DefaultData);
26
27 ::RegCloseKey(hKey);
28
29
30
31 }
4修改用户数据库日志log默认存储路径为UPDATEDATA
#define UPDATELOG "F:\\test"
void UpDatalog()
{
// TODO: Add your control notification handler code here
HKEY hKey;
LPCTSTR log_Set="Software\\Microsoft\\Microsoft SQL Server\\MSSQL10.MSSQL\\MSSQLServer";
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,log_Set,0,KEY_WRITE,&hKey));
if(ret0!=ERROR_SUCCESS){
MessageBox("无法打开文件");
return ;
}
CString logStr=UPDATELOG ;
LPBYTE lpctDataStr=CString_To_LPBYTE(logStr);
DWORD type1=REG_SZ;
DWORD cbData1=logStr.GetLength()+1;
long ret1=::RegSetValueEx(hKey, "Defaultlog", NULL,
type1, lpctDataStr, cbData1);
if(ret1!=ERROR_SUCCESS)
{
MessageBox("错误: 无法修改有关注册表信息!");
return;
}
::RegCloseKey(hKey);
MessageBox("修改成功");
}