Detect BIOS from WinPE: Legacy or UEFI, using vbs // Outputting results from a .exe to .txt

5.9k views Asked by At

Here is my scenario:

I have a server with 2 possible configurations: 2-TB HDD which require no special treatment or 3-TB HDD that require a UEFI BIOS and a GPT partition to boot the OS.

I am trying to create a single installation USB key that is able to detect whether the BIOS is 'legacy' or 'UEFI' and execute a deployment script accordingly.

I looked hard for a WMI that can make the distinction but to no avail.

The closest that I came to a solution is this post: http://social.technet.microsoft.com/Forums/en-US/winserverManagement/thread/6cbb488d-3062-4aad-b712-7a9e4d045b13

detectefi.exe works perfectly in detecting the BIOS type, but I can't output its result so I don't know how to use it.

I have 2 questions:

  1. is there any WMI that I can use to distinguich between my 2 set-ups.

  2. (if the answer for question 1 is no) is there a way to output the results from a C++ compiled .exe file to .txt or any other form and make use of the result (I have no C++ skills at all)

3

There are 3 answers

1
ToastMan On BEST ANSWER

If anyone is interested how I fixed the problem. I just created a vbs linking to the .exe

    Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("detectefi.exe")
Set objStdOut = objWshScriptExec.StdOut

dim isLegacy
dim isUefi

isLegacy = false
isUefi = false

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine

   if strLine = "Legacy" then
      isLegacy = true
   end if

   if strLine = "UEFI" then
      isUefi = true
   end if
Wend


if isLegacy then
   wscript.echo "this is legacy"

    set objShell = Wscript.CreateObject("WScript.Shell")
    objShell.Run "2TBdeploy.cmd",1,True
    set objShell = Nothing

end if


if isUefi then
   wscript.echo "this is UEFI"

    set objShell = Wscript.CreateObject("WScript.Shell")
    objShell.Run "3TBdeploy.cmd",1,True
    set objShell = Nothing

end if
0
MaverickAsc On

This is real easy to detect without using any special utilities and using command line native to Windows OS.

BCDEDIT /ENUM will provide you the default bootloader. This is what can be used to distinguish UEFI and BIOS machines, like so:

path                    \EFI\Microsoft\Boot\bootmgfw.efi

You can then process the output using oShell.Exec as described above.

0
Sweetu Ghadage On

import os

if os.path.exists("/sys/firmware/efi"): print "uefi" else: print "bios"