hasis
驱动牛犊
驱动牛犊
  • 注册日期2003-01-07
  • 最后登录2006-04-03
  • 粉丝0
  • 关注0
  • 积分57分
  • 威望12点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
阅读:1854回复:1

禁用硬件后,如何判断是否需要重起

楼主#
更多 发布于:2005-06-08 17:07
众位大哥:

求教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?

最新喜欢:

bigstonebigsto...
大学课程加上语文吧,否则在驱网里都不会提问题:)
bigstone
驱动牛犊
驱动牛犊
  • 注册日期2007-07-01
  • 最后登录2009-04-05
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2009-04-02 21:43
我也有相同的疑问,不知哪位大哥能指点下
游客

返回顶部