c# – 如何检测WinPE(4)是否已从UEFI或BIOS启动?
发布时间:2020-12-15 07:51:03 所属栏目:百科 来源:网络整理
导读:我正在寻找一种方法来可靠地检测我何时启动到WinPE 4(power shell)(或WinPE 3(vbs)作为替代),我是从UEFI或B IOS系统启动的吗? (因为我在受限制的环境中没有运行第三方exe) 这会显着改变我在分区布局更改和格式时对Windows部署进行分区的方式. (GPT与MBR等)
我正在寻找一种方法来可靠地检测我何时启动到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() } 为了得到一个简单的旗帜,这似乎相当于顶部. 解决方法
从某种意义上讲,它仍然需要来自powershell的互操作,但如果您使用(或可以调用),则互操作代码可能更整洁:
GetFirmwareType() .
这将返回一个记录在here的FIRMWARE_TYPE枚举.我不敢相信,在Windows 8中引入了两个函数并由kernel32.dll导出,Microsoft自己的文档指向“使用虚拟变量”! 在内部,GetFirmwareType调用NtQuerySystemInformation.我将深入研究它在做什么,但我认为它不一定会具有启发性. 不幸的是,这只适用于PE4(Windows 8),因为这些功能只是添加了. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 141.Which tablespaces are mandatory in an Oracle databa
- c# – WP8.1应用程序在调用RequestProductPurchaseAsync时崩
- 《从零开始学Swift》学习笔记(Day 52)――Cocoa错误处理模
- ruby-on-rails – Ruby on Rails有什么类似的MAMP吗?
- 理解React组件的生命周期
- oracle job 每分钟执行一次
- VUE JS 使用组件实现双向绑定的示例代码
- 有十件事情Flex开发者需要知道
- c# – 无法将类型’object’隐式转换为’Microsoft.Office.
- ruby-on-rails-4 – 将bootstrap-sass gem包装在另一个gem中