阅读:1553回复:6
关于设备驱动卸载!!!
如何实现类似控制面板里面设备卸载的过程???
当选取了“显示隐藏设备”后,即使没有插入的设备也显示出来了,经过此过程后,再删掉.sys和.inf .pnf后,就清的很干净了! 有没有知道如何实现?(100分或技术交换) |
|
|
沙发#
发布于:2004-09-17 10:53
想
|
|
|
板凳#
发布于:2004-09-17 12:07
[quote]想
|
|
地板#
发布于:2004-09-17 14:55
不咿我用debugView看到的是直接咄入了IRP_MN_REMOVE. :mad:
|
|
|
地下室#
发布于:2004-09-17 15:45
你有没有写处理IRP_SURPRISE_REMOVAL的例程? :)
|
|
5楼#
发布于:2004-09-17 15:58
-- 献给楼主 --
#include <setupapi.h> #ifdef __cplusplus extern "C" { #endif int RemoveDriver(_TCHAR *HardwareID) { HDEVINFO DeviceInfoSet; SP_DEVINFO_DATA DeviceInfoData; DWORD i,err; DeviceInfoSet = SetupDiGetClassDevs(NULL, // All Classes 0, 0, DIGCF_ALLCLASSES ); // All devices on system (include not connected device) //DIGCF_ALLCLASSES|DIGCF_PRESENT flag indicate devices connected(present),hehe if (DeviceInfoSet == INVALID_HANDLE_VALUE) { //Error Report; return 1; } // // Enumerate through all Devices. // DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i=0;SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);i++) { DWORD DataT; LPTSTR p,buffer = NULL; DWORD buffersize = 0; // // We won't know the size of the HardwareID buffer until we call // this function. So call it with a null to begin with, and then // use the required buffer size to Alloc the nessicary space. // Keep calling we have success or an unknown failure. // while (!SetupDiGetDeviceRegistryProperty( DeviceInfoSet, &DeviceInfoData, SPDRP_HARDWAREID, &DataT, (PBYTE)buffer, buffersize, &buffersize)) { if (GetLastError() == ERROR_INVALID_DATA) { // // May be a Legacy Device with no HardwareID. Continue. // break; } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { // // We need to change the buffer size. // if (buffer) LocalFree(buffer); buffer = (char *)LocalAlloc(LPTR,buffersize); } else { // // Unknown Failure. // //Error Report; goto cleanup_DeviceInfo; } } if (GetLastError() == ERROR_INVALID_DATA) continue; // // Compare each entry in the buffer multi-sz list with our HardwareID. // for (p=buffer;*p&&(p<&buffer[buffersize]);p+=lstrlen(p)+sizeof(TCHAR)) { //_tprintf(TEXT("Compare device ID: [%s]\n"),p); if (!_tcscmp(HardwareID,p)) { //_tprintf(TEXT("Found! [%s]\n"),p); // // Worker function to remove device. // if (!SetupDiCallClassInstaller(DIF_REMOVE, DeviceInfoSet, &DeviceInfoData)) { //Error Report; } break; } } if (buffer) LocalFree(buffer); } if ((GetLastError()!=NO_ERROR)&&(GetLastError()!=ERROR_NO_MORE_ITEMS)) { //Error Report; } // // Cleanup. // cleanup_DeviceInfo: err = GetLastError(); SetupDiDestroyDeviceInfoList(DeviceInfoSet); return err; } #ifdef __cplusplus } #endif |
|
|
6楼#
发布于:2004-09-17 16:11
你有没有写处理IRP_SURPRISE_REMOVAL的例程 有写 DecrementIoCount(DeviceObject); deviceExtension->DeviceRemoved = TRUE; CancelPendingIo( DeviceObject ); AbortPipes( DeviceObject ); Irp->IoStatus.Status = STATUS_SUCCESS; IoCopyCurrentIrpStackLocationToNext(Irp); ntStatus = IoCallDriver(stackDeviceObject, Irp); return ntStatus; 基本上好多地方都是抄的,自己弄得不是很懂。 |
|
|