2,302
社区成员
发帖
与我相关
我的任务
分享
BOOL ChangeStatus(DWORD NewStatus, DWORD SelectedItem, HDEVINFO hDevInfo)
{
CString msgstr;
HCURSOR hCursor = NULL;
SP_PROPCHANGE_PARAMS PropChanegeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
hCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
//Get a handle to the selected Item
if(!SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData))
{
msgstr.Format(_T("%d"),GetLastError());
AfxMessageBox(msgstr);
return false;
}
PropChanegeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChanegeParams.Scope = DICS_FLAG_GLOBAL;
PropChanegeParams.StateChange = NewStatus;
if(!SetupDiSetClassInstallParams(hDevInfo,&DeviceInfoData,(SP_CLASSINSTALL_HEADER *)&PropChanegeParams,sizeof(PropChanegeParams)))
{
msgstr.Format(_T("%d"),GetLastError());
AfxMessageBox(msgstr);
return false;
}
if(!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,hDevInfo,&DeviceInfoData))
{
msgstr.Format(_T("%d"),GetLastError());
AfxMessageBox(msgstr);
return false;
}
SetCursor(hCursor);
return true;
}
BOOL ControlDisk(int nStatus)
{
if(-1 == nStatus)
{
return false;
}
CString msgStr;
TCHAR * GUIDString = NULL;
GUID guid;
ZeroMemory(&guid,sizeof(GUID));
GUIDString = _T("36FC9E60-C465-11CF-8056-444553540000");
UuidFromString((unsigned short *)GUIDString,&guid);
HDEVINFO hDevInfo = SetupDiGetClassDevs(&guid,NULL,NULL,DIGCF_PRESENT);
if(INVALID_HANDLE_VALUE == hDevInfo)
{
msgStr.Format(_T("%d"),GetLastError());
AfxMessageBox(msgStr);
return false;
}
DWORD i;
SP_DEVINFO_DATA DeviceInfoData;
ZeroMemory(&DeviceInfoData,sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for(i = 0; SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);++i)
{
if(1 == nStatus)
{
ChangeStatus(DICS_ENABLE,i,hDevInfo);
}
else if(0==nStatus)
{
ChangeStatus(DICS_DISABLE,i,hDevInfo);
}
}
return SetupDiDestroyDeviceInfoList(hDevInfo);
}