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.Diagnostics;
using System.Management;
using DerpingDrivers.Exceptions;
using ExceptionReporting;
using Microsoft.Win32;
@ -15,15 +16,29 @@ namespace DerpingDrivers.Util
{
get
{
var bootmgrDefaultGuid = (string) Registry.GetValue(
@"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{9DEA862C-5CDD-4E70-ACC1-F32B344D4795}\Elements\23000003",
"Element", null);
var connectionOptions =
new ConnectionOptions
{
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true
};
var allowPrereleaseSignatures = (byte[]) Registry.GetValue(
$@"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{bootmgrDefaultGuid}\Elements\16000049",
"Element", default(byte[]));
var managementScope = new ManagementScope(@"root\WMI", connectionOptions);
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