阅读:1914回复:1
禁用硬件后,如何判断是否需要重起
众位大哥:
求教ING... 我使用SetupDiCallClassInstaller禁用硬件设备后(如USB接口),经常会出现设备状态不正常的情况,即设备管理器中显示设备中有一个小的黄叹号。 但如果此时重起系统,则状态改为正常,为什么会出现这种情况呢? 另外,根据MSDN,使用SetupDiCallClassInstaller后,可以通过使用SetupDiGetDeviceInstallParams判断是否需要重起系统生效,但我的使用没有成功,请问为什么? 相关代码如下: BOOL StateChange(DWORD NewState, DWORD SelectedItem,HDEVINFO hDevInfo) { SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)}; SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)}; HCURSOR hCursor; SP_DEVINSTALL_PARAMS OutDevParams = {sizeof(SP_DEVINSTALL_PARAMS)}; TCHAR szParamInf[MAX_PATH] = {0}; // Get a handle to the Selected Item. if (!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData)) { printf(\"EnumDeviceInfo\"); return FALSE; } // Set the PropChangeParams structure. PropChangeParams.ClassInstallHeader.cbSize = sizeof(PropChangeParams.ClassInstallHeader); PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; // PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC ; PropChangeParams.Scope = DICS_FLAG_GLOBAL ; PropChangeParams.StateChange = NewState; PropChangeParams.HwProfile = 0; if (!SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData, (SP_CLASSINSTALL_HEADER *)&PropChangeParams, sizeof(PropChangeParams))) { OutputDebugString(\"SetClassInstallParams Error\"); SetCursor(hCursor); return FALSE; } // Call the ClassInstaller and perform the change. if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &DeviceInfoData)) { memset(szParamInf, 0, MAX_PATH); _stprintf(szParamInf, \"SetupDiCallClassInstaller Error %d\", GetLastError()); OutputDebugString(szParamInf); SetCursor(hCursor); return TRUE; } //check whether or not the user should reboot system if (!SetupDiGetDeviceInstallParams(hDevInfo, &DeviceInfoData, &OutDevParams)) { OutputDebugString(\"SetupDiGetDeviceInstallParams Error\"); return FALSE; } if ((OutDevParams.Flags & DI_NEEDRESTART) || (OutDevParams.Flags & DI_NEEDREBOOT)) { MessageBox(NULL, \"Need reboot system\", \"Memo\", MB_ICONINFORMATION|MB_OK); OutputDebugString(\"The System recommend rebooting system\"); } //不管出现什么情况,OutDevParams.Flags 值始终为DI_CLASSINSTALLPARAMS, WHY? |
|
最新喜欢:bigsto...
|
沙发#
发布于:2009-04-02 21:43
我也有相同的疑问,不知哪位大哥能指点下
|
|