遍历注册表得到所有USB驱动
来源:互联网 发布:南瑞科技 知乎 编辑:程序博客网 时间:2024/05/20 08:43
遍历注册表得到所有USB驱动,并对比是否存在指定驱动,这是为了解决USB驱动重复安装会导致鼠标键盘不可用问题,存在跟驱动包相同的版本,则不安装
// bios.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"//#include "windows.h"#pragma warning(disable:4996)#pragma comment (lib,"Advapi32.lib")#include <afx.h>BOOL USBDriverWin7 = FALSE;// ErrorMessage support function.// Retrieves the system error message for the GetLastError() code.// Note: caller must use LocalFree() on the returned LPCTSTR buffer.static LPCTSTR ErrorMessage(DWORD error){LPVOID lpMsgBuf;FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS,NULL,error,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL);return((LPCTSTR)lpMsgBuf);}// PrintError support function.// Simple wrapper function for error output.static void PrintError(LPCTSTR errDesc){LPCTSTR errMsg = ErrorMessage(GetLastError());_tprintf(TEXT("\n** ERROR ** %s:%d, %s\n"), errDesc, GetLastError(), errMsg);//CString text;//text.Format(_T("%u"), GetLastError());//CString str = errDesc;//str = str + text;//str = str + errMsg;//AfxMessageBox(str);LocalFree((LPVOID)errMsg);}int main(int argc, char* argv[]){HKEY hKEYtmp;HKEY hKEY;//定义有关的hKEY,在查询结束时要关闭 //打开与路径data_Set相关的hKEYLPCTSTR data_Set = _T("SYSTEM\\ControlSet001\\Control\\Class\\{36FC9E60-C465-11CF-8056-444553540000}");//访问注册表,hKEY则保存此函数所打开的键的句柄if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_Set, 0, KEY_READ, &hKEY) != ERROR_SUCCESS){PrintError(_T("RegOpenKeyEx:"));_tprintf(_T("Error: RegOpenKeyEx unable to query information about the registry\n"));return 1;}DWORD dwSubKeyCnt; // 子键的数量 DWORD dwSubKeyNameMaxLen; // 子键名称的最大长度(不包含结尾的null字符) DWORD dwKeyValueCnt; // 键值项的数量 DWORD dwKeyValueNameMaxLen; // 键值项名称的最大长度(不包含结尾的null字符) DWORD dwKeyValueDataMaxLen; // 键值项数据的最大长度(in bytes) if (RegQueryInfoKey(hKEY,NULL,NULL,NULL,&dwSubKeyCnt,&dwSubKeyNameMaxLen,NULL,&dwKeyValueCnt,&dwKeyValueNameMaxLen,&dwKeyValueDataMaxLen,NULL,NULL) != ERROR_SUCCESS ) // Error {PrintError(_T("RegQueryInfoKey:"));_tprintf(_T("Error:RegQueryInfoKey unable to query information about the registry\n"));return 1;}// // 以下代码中的变量dwSubKeyNameMaxLen&dwSubKeyCnt由 // RegQueryInfoKey获取 // LPTSTR lpszSubKeyName = new TCHAR[dwSubKeyNameMaxLen + 1];for (int index = 0; index < dwSubKeyCnt; ++index){hKEYtmp = hKEY;memset(lpszSubKeyName, 0, sizeof(TCHAR)*(dwSubKeyNameMaxLen + 1));DWORD dwNameCnt = dwSubKeyNameMaxLen + 1;int ret = RegEnumKeyEx(hKEY,index,lpszSubKeyName,&dwNameCnt,NULL,NULL,NULL,NULL);if (ret == ERROR_NO_MORE_ITEMS){_tprintf(_T("Error:RegEnumKeyEx ERROR_NO_MORE_ITEMS\n"));//return 1;}if (ret == ERROR_MORE_DATA){_tprintf(_T("Error:RegEnumKeyEx ERROR_MORE_DATA\n"));//return 1;}if (ret != ERROR_SUCCESS) // Error {PrintError(_T("RegEnumKeyEx:"));_tprintf(_T("Error:RegEnumKeyEx unable to query information about the registry\n")); return 1; }printf("lpszSubKeyName:%s\n", lpszSubKeyName); /*for (unsigned int index = 0; index < dwKeyValueCnt; ++index){LPTSTR lpszKeyValueName = new TCHAR[dwKeyValueNameMaxLen + 1];memset(lpszKeyValueName, 0, sizeof(TCHAR)*(dwKeyValueNameMaxLen + 1));DWORD dwNameCnt = dwKeyValueNameMaxLen + 1;DWORD dwKeyValueType;LPBYTE lpbKeyValueData = new BYTE[dwKeyValueDataMaxLen];DWORD dwKeyValueDataLen;int ret = RegEnumValue(hKEY,index,lpszKeyValueName,&dwNameCnt,NULL,&dwKeyValueType,lpbKeyValueData,&dwKeyValueDataLen);if (ret != ERROR_SUCCESS){PrintError(_T("RegEnumValue:"));_tprintf(_T("Error:RegEnumValue unable to query information about the registry\n"));return 1;}printf("lpszKeyValueName:%s\n", lpszKeyValueName); delete[] lpszKeyValueName; delete[] lpbKeyValueData;} */if (RegOpenKeyEx(hKEYtmp, lpszSubKeyName, 0, KEY_READ, &hKEYtmp) != ERROR_SUCCESS){PrintError(_T("RegOpenKeyEx:"));_tprintf(_T("Error: RegOpenKeyEx unable to query information about the registry\n"));return 1;}TCHAR DriverVersion[256];TCHAR DriverDate[256];DWORD dwSzType = REG_SZ;DWORD dwSizeDriverVersion = sizeof(DriverVersion);DWORD dwSizeDriverDate = sizeof(DriverDate);if (RegQueryValueEx(hKEYtmp, _T("DriverVersion"), 0, &dwSzType, (LPBYTE)&DriverVersion, &dwSizeDriverVersion) != ERROR_SUCCESS){//PrintError(_T("RegQueryValueEx:")); _tprintf(_T("Error:RegQueryValueEx unable to query information about the registry\n"));// return 1;} CString USBVersionWin7 = { _T("10.0.14393.1358") }; if (USBVersionWin7 == DriverVersion) { _tprintf(_T("DriverVersion:%s\n"), DriverVersion); BOOL USBtmp = TRUE; if (USBtmp) USBDriverWin7 = TRUE; }RegCloseKey(hKEYtmp);}//for delete[] lpszSubKeyName; //程序结束,关闭打开的hKEYRegCloseKey(hKEY);//system(_T("pause"));return 0;}
阅读全文
0 0
- 遍历注册表得到所有USB驱动
- 遍历注册表某键下的所有子键
- 遍历注册表下所有子键
- 遍历注册表某键下的所有子键
- 【Python】遍历文件夹,得到所有文件
- C++遍历所有IE浏览器,得到里面的所有元素
- C++遍历所有IE浏览器,得到里面的所有元素
- usb 驱动安装过程中对注册表的改动
- 遍历注册表某键下的所有子键及其KeyValue
- C++ 遍历注册表项下的所有键和值
- php遍历文件夹下面的所有文件,得到文件路径
- 注册表遍历
- 注册表遍历
- 遍历注册表
- 删除USB转串口的所有驱动 win7可用
- 串口编程-枚举遍历串口、获取PC所有串口名称、遍历注册表项、RegEnumValue用法
- 利用 SHDocVw::IShellWindowsPtr m_spSHWinds 遍历所有IE浏览器,得到里面的所有元素
- 通过注册表禁用USB
- Codeforces 278B Books
- 17暑假多校联赛2.6 HDU 6050 Funny Function
- 使用npm uninstall卸载express无效
- activity进出场动画以及动画失效问题
- 编译android源码7---android 源码目录结构
- 遍历注册表得到所有USB驱动
- java项目中发送邮件的整体流程
- The Worm Turns
- Latex数学符号使用大全
- %2d、%2u输出格式含义
- 多项式的加法和乘法算术运算的C++实现
- 逃跑的拉尔夫(将深搜进行到底!!!)
- 独木舟上的旅行
- Leetcode87. Scramble String