如何知道初始即插即用枚举何时在 Windows 中完成
How to know when initial plug and play enumeration is complete in Windows
我正在编写一个自动启动的Windows服务。似乎我的服务在 Windows 完成枚举硬件之前启动;特别是USB闪存驱动器。无论如何,有没有知道Windows何时完成其初始硬件扫描?我很确定有,因为当扫描确定需要重新启动才能完成硬件安装时,资源管理器将显示提示。我想过睡很久。我宁愿找到一个更优雅的解决方案。我正在使用C++使用Visual Studio 2017进行开发,并针对Windows 7和Windows 10。
我不知道
这是否只是延迟了我的应用程序足够长的时间以使所有驱动器都显示出来,或者它是否强制驱动器显示。这是我的解决方案:
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#include <windows.h>
#include <cfgmgr32.h>
#include <tchar.h>
#pragma comment(lib,"cfgmgr32.lib")
INT _tmain(){
DEVINST diDevice = 0;
CONFIGRET crErr = CM_Locate_DevInst(&diDevice,nullptr,CM_LOCATE_DEVNODE_NORMAL);
if (crErr == CR_SUCCESS){
crErr = CM_Reenumerate_DevNode(diDevice,CM_REENUMERATE_SYNCHRONOUS);
if (crErr == CR_SUCCESS){
_tprintf(TEXT("Finished enumn"));
}else{
_tprintf(TEXT("Enum failed: %un"),(UINT)CM_MapCrToWin32Err(crErr,0));
}
}else{
_tprintf(TEXT("Locate failed: %un"),(UINT)CM_MapCrToWin32Err(crErr,0));
}
return 0;
}
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux for Windows上编译C++代码时出错
- 何时在引用或唯一指针上使用移动语义
- 在Windows上用C++裁剪HBITMAP
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 如何知道初始即插即用枚举何时在 Windows 中完成
- C++ - 我需要一个宏或环境变量来检测我何时在 Windows 上运行 bazel
- 何时调用 Windows 控制台应用程序需要 CoInitialize
- 在Windows上,何时有必要将附加到目录路径上,以使_stat成功
- 如何检测Windows开始菜单/开始屏幕何时打开
- 如何知道何时将新文件添加到 Windows 中的文件系统
- 何时销毁 Windows 窗体数据源
- 如何在 Windows Mobile 6.5 (c++) 中判断何时按下某个键
- 何时将 Windows 挂钩添加到钩子链中
- 如何在 Windows 上使用 GetSave文件名检测"Save as type:"组合框何时更改?
- 何时使用虚拟内存(windows)
- 检测应用程序何时在Windows中被卸载
- Windows错误报告何时创建转储文件?它是否可配置?这在Windows 7中有改变吗?
- (Windows)何时删除对象和设备上下文
- 如何使用C++侦听/识别程序何时在 Windows 中运行