Fix KPH install check and change KPH driver start to Auto
@@ -91,7 +91,12 @@ NTSTATUS KphConnect2(
_In_ PWSTR FileName
)
{
- return KphConnect2Ex(DeviceName, FileName, NULL);
+ KPH_PARAMETERS parameters;
+
+ parameters.SecurityLevel = KphSecuritySignatureCheck;
+ parameters.CreateDynamicConfiguration = TRUE;
+
+ return KphConnect2Ex(DeviceName, FileName, &parameters);
}
NTSTATUS KphConnect2Ex(
@@ -117,12 +122,12 @@ NTSTATUS KphConnect2Ex(
status = KphConnect(fullDeviceName);
- if (status == STATUS_ADDRESS_ALREADY_EXISTS)
+ if (NT_SUCCESS(status) || status == STATUS_ADDRESS_ALREADY_EXISTS)
return status;
// Load the driver, and try again.
- KphInstall(DeviceName, FileName);
+ KphInstallEx(DeviceName, FileName, Parameters);
// Try to open the device again.
@@ -281,7 +286,7 @@ NTSTATUS KphInstallEx(
return STATUS_OBJECT_NAME_NOT_FOUND;
}
- if (NT_SUCCESS(NtOpenProcessToken(
+ if (NT_SUCCESS(status = NtOpenProcessToken(
NtCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES,
&tokenHandle
@@ -291,6 +296,9 @@ NTSTATUS KphInstallEx(
NtClose(tokenHandle);
}
+ if (!NT_SUCCESS(status))
+ goto CleanupExit;
+
keyName = PhConcatStrings(
2,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
@@ -339,7 +347,7 @@ NTSTATUS KphInstallEx(
if (!NT_SUCCESS(status = NtSetValueKey(keyHandle, &valueName, 0, REG_DWORD, &parameters, sizeof(ULONG))))
goto CleanupExit;
- parameters = SERVICE_DEMAND_START;
+ parameters = SERVICE_AUTO_START;
RtlInitUnicodeString(&valueName, L"Start");
if (!NT_SUCCESS(status = NtSetValueKey(keyHandle, &valueName, 0, REG_DWORD, &parameters, sizeof(ULONG))))
goto CleanupExit;
