阅读:1563回复:4
注册表的访问
请问我在VC++ 下访问注册表的时候只能查询键值两次,第三次查询就返回错误信息,一般返回值为234,是什么原因呢,请高手指教。谢谢!
|
|
沙发#
发布于:2005-01-26 18:26
代码贴出来吧
|
|
|
板凳#
发布于:2005-01-27 09:52
谢谢大佬,敬请大佬不吝指教,还想问一下,当前系统盘如何确定。
以下是访问注册表的代码,请指点! void CSonicsUnDlg::OnButtonContinue() { // TODO: Add your control notification handler code here CFile fn ; GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(FALSE); SetDlgItemText(IDC_EDIT_PROMPT, "\r\n Deleting registry entries...\ \r\n Deleting files...") ; HKEY RegHandle ; long lResult ; DWORD type_1 = REG_SZ ; DWORD cbData_1 = 80 ; UCHAR SonicsInfPath[80] ; CString str; CFileFind SonicsFinder ; FindMyFilePath("C:\\", "WINNT") ; char bCnt = SonicsPath.Find("WINNT") ; if (bCnt == -1) { FindMyFilePath("D:\\", "WINNT") ; bCnt = SonicsPath.Find("WINNT") ; if (bCnt != -1) { FindMyFilePath(SonicsPath + "\\", "Sonics.sys") ; if (SonicsPath == "D:\\WINNT\\system32\\drivers\\Sonics.sys") { if (SonicsFinder.FindFile(SonicsPath)) { fn.Remove(SonicsPath) ; } } //if found the system path //then query the inf path str = "System\\ControlSet001\\Enum\\USB\\Vid_0403&Pid_1975\\NTNE16Y1" ; long lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, NULL, KEY_READ, &RegHandle); if (lResult == ERROR_SUCCESS) { lResult = ::RegQueryValueEx(RegHandle, "driver", NULL, &type_1, SonicsInfPath, &cbData_1) ; ::RegCloseKey(RegHandle) ; if (lResult == ERROR_SUCCESS) { //query the info key value str.Format("%s", "System\\ControlSet001\\Control\\Class\\" ) ; str = str + SonicsInfPath ; lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, NULL, KEY_READ, &RegHandle) ; if (lResult == ERROR_SUCCESS) { lResult = ::RegQueryValueEx(RegHandle, "InfPath", NULL, &type_1, SonicsInfPath, &cbData_1) ; ::RegCloseKey(RegHandle) ; if (lResult == ERROR_SUCCESS) { // SonicsPath += "\\" ; // FindMyFilePath(SonicsPath, "inf") ; SonicsPath = "D:WINNT\\" ; FindMyFilePath(SonicsPath, SonicsInfPath) ; BOOL bResult = SonicsFinder.FindFile(SonicsPath) ; if (bResult) { fn.Remove(SonicsPath) ; } bCnt = SonicsPath.Replace(".inf", ".PNF") ; if (bCnt) { if (SonicsFinder.FindFile(SonicsPath)) { fn.Remove(SonicsPath) ; } SonicsFinder.Close(); } } } } } //query the SonicsUn.exe file path str = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Sonics" ; lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, NULL, KEY_READ, &RegHandle) ; if (lResult == ERROR_SUCCESS) { lResult = ::RegQueryValueEx(RegHandle, "UninstallString", NULL, &type_1, SonicsInfPath, &cbData_1) ; ::RegCloseKey(RegHandle) ; if (lResult == ERROR_SUCCESS) { //delete the SonicsUn.exe file str = SonicsInfPath ; bCnt = str.Find("SonicsUN.exe") ; str = str.Left(bCnt+12) ; if (SonicsFinder.FindFile(str)) { fn.Remove(str) ; } //delete the Sonics.dll file str = str + "Sonics.dll" ; if (SonicsFinder.FindFile(str)) { fn.Remove(str) ; } } } } } //show message on the screen SetDlgItemText(IDC_EDIT_PROMPT, "\r\n Deleting registery entries...\ \r\n Deleting files... \ \r\n Uninstall complete, press Finish to exit" ) ; SetDlgItemText(IDCANCEL, "Finish") ; } |
|
地板#
发布于:2005-01-27 13:14
请问我在VC++ 下访问注册表的时候只能查询键值两次,第三次查询就返回错误信息,一般返回值为234,是什么原因呢,请高手指教。谢谢! 你的代码有什么问题吗? 查不到就是指定键值不存在, 如果想得到某键值下的所有子键,请使用RegEnumKey或RegEnumKeyEx 得到系统目录使用GetSystemDirectory |
|
|
地下室#
发布于:2005-01-28 13:06
谢谢指点, 我的代码是第三次查询的时候返回错误,不知道是什么原因,我用RegEnumKeyEx()同样返回的是错误信息。指定的键值是存在的,我去掉前面的一次查询后就可以访问了,请继续指教。谢谢了! ;)
|
|