防止移动云电脑关机的代码,拿去用吧,不用谢,c写的
拦截Windows关机事件,直接抛弃
- #include <ntddk.h>// 你的PnP驱动的设备扩展typedef struct _DEVICE_EXTENSION { PDEVICE_OBJECT DeviceObject; // 其他字段} DEVICE_EXTENSION, *PDEVICE_EXTENSION;NTSTATUS MyDeviceAdd ( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject){ NTSTATUS status; PDEVICE_OBJECT deviceObject; PDEVICE_EXTENSION deviceExtension; // 创建你的设备对象 status = IoCreateDevice( DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject ); if (!NT_SUCCESS(status)) { return status; } deviceExtension = (PDEVICE_EXTENSION) deviceObject->DeviceExtension; deviceExtension->DeviceObject = deviceObject; // 添加类似以下代码来设置你的设备的电源相关函数 deviceObject->Flags |= DO_POWER_INRUSH; // 设置你的设备以进行电源IRP处理 deviceObject->Flags |= DO_POWER_PAGABLE; return status;}NTSTATUS MyPower ( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp){ PIO_STACK_LOCATION stack; stack = IoGetCurrentIrpStackLocation(Irp); if (stack->MinorFunction == IRP_MN_SET_POWER) { if (stack->Parameters.Power.Type == SystemPowerState) { // 检查是否是要到关机状态 if (stack->Parameters.Power.State.SystemState == PowerSystemShutdown) { // 你可以在这里编写代码来拒绝关机操作,比如直接返回 STATUS_SUCCESS。 return STATUS_SUCCESS; } } } // 默认情况下,所有其他 IRPs 都会通过 return IoPassIrpDown(DeviceObject, Irp);}VOID DriverUnload ( IN PDRIVER_OBJECT DriverObject){ PDEVICE_OBJECT deviceObject; deviceObject = DriverObject->DeviceObject; while (deviceObject) { PDEVICE_OBJECT nextDeviceObject; nextDeviceObject = deviceObject->NextDevice; IoDeleteDevice(deviceObject); deviceObject = nextDeviceObject; }}NTSTATUS DriverEntry ( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath){ NTSTATUS status; DriverObject->DriverUnload = DriverUnload; DriverObject->DriverExtension->AddDevice = MyDeviceAdd; DriverObject->MajorFunction[IRP_MJ_POWER] = MyPower; return STATUS_SUCCESS;}