VOID EvtDeviceCleanup( _In_ WDFOBJECT Object ) { WDFDEVICE device = (WDFDEVICE) Object; PDEVICE_CONTEXT deviceContext = GetDeviceContext(device); NTSTATUS status; WDFKEY key = NULL; UNICODE_STRING pdoString = {0}; DECLARE_CONST_UNICODE_STRING(deviceSubkey, SERIAL_DEVICE_MAP); if (deviceContext->CreatedLegacyHardwareKey == TRUE) { RtlInitUnicodeString(&pdoString, deviceContext->PdoName); status = WdfDeviceOpenDevicemapKey(device, &deviceSubkey, KEY_SET_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &key); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Failed to open DEVICEMAP\\SERIALCOMM key 0x%x", status); goto exit; } status = WdfRegistryRemoveValue(key, &pdoString); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Failed to delete %S key, 0x%x", pdoString.Buffer, status); goto exit; } status = WdfRegistryRemoveKey(key); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Failed to delete %S, 0x%x", SERIAL_DEVICE_MAP, status); goto exit; } } exit: if (key != NULL) { WdfRegistryClose(key); key = NULL; } return; }
//.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- DriverParametersKeyDelete -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- // NTSTATUS DriverParametersKeyDelete( WDFDRIVER Driver, DtString* pKeyName) { NTSTATUS NtStatus; WDFKEY ParametersKey; WDFKEY Key = NULL; DT_ASSERT(KeGetCurrentIrql()<=PASSIVE_LEVEL); // Open the drivers parameters key (under services) NtStatus = WdfDriverOpenParametersRegistryKey(Driver, KEY_WRITE, WDF_NO_OBJECT_ATTRIBUTES, &ParametersKey); if (!NT_SUCCESS(NtStatus)) { DtDbgOut(ERR, SAL, "WdfDriverOpenParametersRegistryKey failed. Error: 0x%x", NtStatus); return NtStatus; } // Open subkey NtStatus = WdfRegistryOpenKey(ParametersKey, pKeyName, KEY_WRITE, WDF_NO_OBJECT_ATTRIBUTES, &Key); if (!NT_SUCCESS(NtStatus)) { if (NtStatus == STATUS_OBJECT_NAME_NOT_FOUND) DtDbgOut(MAX, SAL, "WdfRegistryOpenKey error:'STATUS_OBJECT_NAME_NOT_FOUND'"); else DtDbgOut(ERR, SAL, "WdfRegistryOpenKey failed. Error: 0x%x", NtStatus); } if (NT_SUCCESS(NtStatus)) { // Delete the key NtStatus = WdfRegistryRemoveKey(Key); if (!NT_SUCCESS(NtStatus)) DtDbgOut(ERR, SAL, "WdfRegistryRemoveKey failed. Error: 0x%x", NtStatus); else Key = NULL; } if (Key != NULL) WdfRegistryClose(Key); WdfRegistryClose(ParametersKey); return NtStatus; }