szukam sposób, aby niezawodnie wykrywać kiedy uruchomi się WinPE 4 (PowerShell) (lub WinPE 3 (VBS) jako alternatywnego) ja uruchamiany z UEFI BIOS lub System? (bez uruchamiania exe trzeciej partii, jak jestem w ograniczonym środowisku)Jak wykryć, czy WinPE (4) został uruchomiony z UEFI lub BIOS?
to znacząco zmienia sposób będę partycjonowanie wdrażania systemu Windows jako zmiany układu partycji i format. (GPT kontra MBR, etc)
mam jeden roboczy, który jest adaptacją kodu w PowerShell v3 this C++ ale czuje się dość hack-owski:
## 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()
}
To wydaje się całkiem na wierzchu tylko aby uzyskać prostą flagę.
Czy ktoś wie, czy istnieje lepszy sposób na zrobienie tego?
to nie jest to, czy jestem w WinPE na początku. Właśnie wtedy, gdy jestem w PE, zostałem uruchomiony przez UEFI lub Legacy BIOS. – RogerWilco