1
0

Updated AllowPrereleaseSignatures to read value via WMI

This commit is contained in:
Benjamin Höglinger-Stelzer 2018-11-12 02:05:14 +01:00
parent 2d23832f9c
commit 8ad0aeede6

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Management;
using DerpingDrivers.Exceptions; using DerpingDrivers.Exceptions;
using ExceptionReporting; using ExceptionReporting;
using Microsoft.Win32; using Microsoft.Win32;
@ -15,15 +16,29 @@ namespace DerpingDrivers.Util
{ {
get get
{ {
var bootmgrDefaultGuid = (string) Registry.GetValue( var connectionOptions =
@"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{9DEA862C-5CDD-4E70-ACC1-F32B344D4795}\Elements\23000003", new ConnectionOptions
"Element", null); {
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true
};
var allowPrereleaseSignatures = (byte[]) Registry.GetValue( var managementScope = new ManagementScope(@"root\WMI", connectionOptions);
$@"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{bootmgrDefaultGuid}\Elements\16000049",
"Element", default(byte[]));
return allowPrereleaseSignatures != null && int.Parse(allowPrereleaseSignatures[0].ToString()) > 0; using (var bootMgrObj = new ManagementObject(managementScope,
new ManagementPath(
"root\\WMI:BcdObject.Id=\"{fa926493-6f1c-4193-a414-58f0b2456d1e}\",StoreFilePath=\"\""), null))
{
var inParams = bootMgrObj.GetMethodParameters("GetElement");
inParams["Type"] = (uint) 0x16000049;
var outParams = bootMgrObj.InvokeMethod("GetElement", inParams, null);
var outObj = (ManagementBaseObject) outParams?.Properties["Element"].Value;
var allowPrereleaseSignatures = outObj != null && (bool) outObj.GetPropertyValue("Boolean");
return allowPrereleaseSignatures;
}
} }
set set