VC操作注册表

 

1.VC读取注册表信息:

  HKEY hKEY;
  LPCTSTR data_Set="SOFTWARE//YeeTe//SMS";
  long ret5=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set, 0, KEY_WRITE|KEY_READ, &hKEY));
  //long ret0=::RegDeleteKey(hKEY,"sqlAddress");
  long ret0=::RegDeleteValue(hKEY,"sqlAddress");
  long ret1=::RegDeleteValue(hKEY,"sqlName");
  long ret2=::RegDeleteValue(hKEY,"sqlPwd");
  long ret3=::RegDeleteValue(hKEY,"smsName");
  long ret4=::RegDeleteValue(hKEY,"smsPwd");
  if(ret1!=ERROR_SUCCESS||ret2!=ERROR_SUCCESS||ret3!=ERROR_SUCCESS||ret4!=ERROR_SUCCESS)
  {
   AfxMessageBox("当前所用注册表键删除错误,请重试!");
  }

2.VC写注册表信息:

 HKEY hKEY;
 LPCTSTR data_Set="SOFTWARE//YeeTe//SMS";
 long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set, 0, KEY_READ, &hKEY));
 //查询sql地址
 LPBYTE sqlAdd_Get=new BYTE[80];
 DWORD type_1=REG_SZ ; DWORD cbData_1=80;
 long ret1=::RegQueryValueEx(hKEY, "sqlAddress", NULL, &type_1, sqlAdd_Get, &cbData_1);

 // 查询SQL用户名
 LPBYTE sqlName_Get=new BYTE [80];
 DWORD type_2=REG_SZ; DWORD cbData_2=80;
 long ret2=::RegQueryValueEx(hKEY, "sqlName", NULL,&type_2,sqlName_Get,&cbData_2);

 // 查询SQL密码
 DWORD cbData_3=80;
 LPBYTE sqlPass_Get=new BYTE [80];
 long ret3=::RegQueryValueEx(hKEY, "sqlPwd", NULL,&type_2,sqlPass_Get,&cbData_3);

 //查询SMS用户名
 DWORD cbData_4=80;
 LPBYTE smsName_Get=new BYTE [80];
 long ret4=::RegQueryValueEx(hKEY, "smsName", NULL,&type_2,smsName_Get,&cbData_4);

 //查询SMS密码
 DWORD cbData_5=80;
 LPBYTE smsPwd_Get=new BYTE [80];
 long ret5=::RegQueryValueEx(hKEY, "smsPwd", NULL,&type_2,smsPwd_Get,&cbData_5);

 if(ret0!=ERROR_SUCCESS||ret1!=ERROR_SUCCESS||ret2!=ERROR_SUCCESS||ret3!=ERROR_SUCCESS||ret4!=ERROR_SUCCESS||ret5!=ERROR_SUCCESS)
 {
  //AfxMessageBox("错误: 无法查询有关注册表信息!");
  CSmsDlg dlg;
  dlg.DoModal();
 }

阅读更多
文章标签: byte null sms sql
上一篇VC操作注册表(转)
下一篇读写注册表(转)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭