资源描述:
《vc 实现光驱、软驱、usb的禁用和启用(vc cd-rom driver, floppy drive, usb disable and enable)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、vc++实现光驱、软驱、usb的禁用和启用(Vc++CD-ROMdriver,floppydrive,USBdisableandenable)VC++serialprogrammingtechnologyVC++fordisabledandenabledCD-ROM,floppydrive,USB2007-06-2817:58:21VC++serialprogrammingtechnologyVC++fordisabledandenabledCD-ROM,floppydrive,USBRefertothecodethatyouprovidef
2、orthenetworkcardtodisable,theCD-ROMdrive,floppydrive,USBenableanddisable.Themainimplementationcodeisasfollows://thenecessaryheaderfilesandlinkstotheLIBfile#include#include#pragmacomment(LIB,"setupapi.lib")#pragmacomment(LIB,"shlwapi.lib")Informationse
3、t//device(Itranslateditforthedeviceinformationset)HDEVINFOhDevInfo=NULL;//errormessagesVoidFormatMSG(DWORDdwError,LPTSTR*lpszMsg){BOOLbOk=FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
4、FORMAT_MESSAGE_ALLOCATE_BUFFER,NULL,dwError,MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED)
5、,(LPTSTR)lpszMsg,0,NULL);If(...BOk){HMODULEhDll=LoadLibraryEx(_T("netmsg.dll")),NULL,DONT_RESOLVE_DLL_REFERENCES);If(NULL==hDll){FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
6、FORMAT_MESSAGE_FROM_SYSTEM,HDll,DwError,MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),(LPTSTR)lps
7、zMsg,0,NULL);FreeLibrary(hDll);}}}BOOLChangeStatus(DWORDNewStatus,DWORDSelectedItem,HDEVINFOhDevInfo){LPTSTRlpszMsg=NULL;HCURSORhCursor=NULL;Try{SP_PROPCHANGE_PARAMSPropChangeParams={sizeof(SP_CLASSINSTALL_HEADER)};SP_DEVINFO_DATADeviceInfoData={sizeof(SP_DEVINFO_DATA)};HCu
8、rsor=SetCursor(LoadCursor(NULL,IDC_WAIT));GetahandletotheSelected//Item.If(?SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData)){FormatMSG(GetLastError(),&lpszMsg);ThrowlpszMsg;}ThePropChangeParamsstructure.//SetPropChangeParams.ClassInstallHeader.InstallFunction=D
9、IF_PROPERTYCHANGE;PropChangeParams.Scope=DICS_FLAG_GLOBAL;PropChangeParams.StateChange=NewStatus;If(...SetupDiSetClassInstallParams(hDevInfo,&DeviceInfoData,(SP_CLASSINSTALL_HEADER*)&PropChangeParams),Sizeof(PropChangeParams)){FormatMSG(GetLastError(),&lpszMsg);ThrowlpszMsg
10、;}CalltheClassInstallerandperformthe//change.If(?SetupDiCallClassInstaller(DIF_PRO