我正在寻找一种方法来可靠地检测我何时启动到WinPE 4(power
shell)(或WinPE 3(vbs)作为替代),我是从UEFI或B
IOS系统启动的吗? (因为我在受限制的环境中没有运行第三方exe)
这会显着改变我在分区布局更改和格式时对Windows部署进行分区的方式. (GPT与MBR等)
我有一个工作,它是在PowerShell v3中修改this C++代码,但它感觉非常hack-ish:
## Check if we can get a dummy flag from the UEFI via the Kernel ## [Bool] check the result of the kernel's fetch of the dummy GUID from UEFI ## The only way I found to do it was using the C++ compiler in powershell Function Compile-UEFIDectectionClass{ $win32UEFICode= @' using System; using System.Runtime.InteropServices; public class UEFI { [DllImport("kernel32.dll")] public static extern UInt32 GetFirmwareEnvironmentvariableA([MarshalAs(UnmanagedType.LPWStr)] string lpName,[MarshalAs(UnmanagedType.LPWStr)] string lpGuid,IntPtr pBuffer,UInt32 nSize); public static UInt32 Detect() { return GetFirmwareEnvironmentvariableA("","{00000000-0000-0000-0000-000000000000}",IntPtr.Zero,0); } } '@ Add-Type $win32UEFICode } ## A Function added just to check if the assembly for ## UEFI is loaded as is the name of the class above in C++. Function Check-IsUEFIClassLoaded{ return ([System.AppDomain]::CurrentDomain.GetAssemblies() | % { $_.GetTypes()} | ? {$_.FullName -eq "UEFI"}).Count } ## Just incase someone was to call my code without running the Compiled code run first If (!(Check-IsUEFIClassLoaded)){ Compile-UEFIDectectionClass } ## The meat of the checking. ## Returns 0 or 1 ([BOOL] if UEFI or not) Function Get-UEFI{ return [UEFI]::Detect() }
解决方法
原文地址:https://www.jb51.cc/csharp/99681.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。