Jump to content

Check if Win10 system is LEGACY or UEFI installed


ModemJunki
 Share

Recommended Posts

So there was a topic on the General Help and Support board where the poster mentioned it was not easy to check if the system was installed with UEFI or legacy mode and it got me looking down a rabbit hole. Apparently you can't just whip up a simple WMI query to find that out.

But I did find that you can read the output of bcdedit.exe to check if the system is using winload.efi or winload.exe, so then I got stuck because bcdedit doesn't play nice with StdoutRead. Finally I discovered that toggling Wow64DisableWow64FsRedirection would make it all work together.

I hope this helps someone. Maybe it can be simplified, I'm no expert. 🤨

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
$aArray = StringSplit(_getDOSOutput("bcdedit.exe"), @CRLF)
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0)

For $i = 1 To UBound($aArray) - 1
    Select
        Case StringInStr($aArray[$i], 'Windows Boot Loader') And StringInStr($aArray[$i + 3], 'device partition=C:') And StringInStr($aArray[$i + 4], 'winload.efi')
            ConsoleWrite("UEFI mode" & @CRLF)
        Case StringInStr($aArray[$i], 'Windows Boot Loader') And StringInStr($aArray[$i + 3], 'device partition=C:') And StringInStr($aArray[$i + 4], 'winload.exe')
            ConsoleWrite("Legacy BIOS" & @CRLF)
    EndSelect
Next

Func _getDOSOutput($command, $wd = '') ; https://www.autoitscript.com/forum/topic/190249-get-result-of-shellexecute/
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, $wd, @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput

 

Always carry a towel.

Link to comment
Share on other sites

On 10/18/2019 at 11:14 PM, TheDcoder said:

Just a heads up, this will fail if the system partition drive letter is not C (it can be changed by the user)

Yes, absolutely correct! But we can fix it with EnvGet (and of course, this requires admin).

#RequireAdmin

$systemdrive = EnvGet('systemdrive')

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
$aArray = StringSplit(_getDOSOutput("bcdedit.exe"), @CRLF)
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0)

For $i = 1 To UBound($aArray) - 1
    Select
        Case StringInStr($aArray[$i], 'Windows Boot Loader') And StringInStr($aArray[$i + 3], 'device partition=' & $systemdrive) And StringInStr($aArray[$i + 4], 'winload.efi')
            ConsoleWrite("UEFI mode" & @CRLF)
        Case StringInStr($aArray[$i], 'Windows Boot Loader') And StringInStr($aArray[$i + 3], 'device partition=' & $systemdrive) And StringInStr($aArray[$i + 4], 'winload.exe')
            ConsoleWrite("Legacy BIOS" & @CRLF)
    EndSelect
Next

Func _getDOSOutput($command, $wd = '') ; https://www.autoitscript.com/forum/topic/190249-get-result-of-shellexecute/
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, $wd, @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput

 

Always carry a towel.

Link to comment
Share on other sites

5 hours ago, czyt said:

maybe  this will do the trick  https://www.autoitscript.com/forum/topic/180322-_isuefiboot%E2%80%94%E2%80%94detemine-the-current-os-is-boot-in-uefi-mode-or-not/ 

Nice, I like the idea of a true/false return.

 

Always carry a towel.

Link to comment
Share on other sites

3 hours ago, coffeeturtle said:

Any ideas if the system returns true UEFI is enabled, but you are not able to enter UEFI ... just the legacy BIOS. How to correct this?

 

I think this would be hardware specific. Not all systems have an UEFI shell in their firmware.

Always carry a towel.

Link to comment
Share on other sites

5 minutes ago, ModemJunki said:

I think this would be hardware specific. Not all systems have an UEFI shell in their firmware.

Thanks. I used to be able to access the UEFI settings. The last thing I did was turn off the WiFi card as it wasn't necessary at the time in the UEFI settings. Of course, now I need to turn it back on and going though the Legacy BIOS the setting isn't there.

I believe the machine was still Windows 7, but upgraded to Windows 10 when the free offer was first available.

I know these forums aren't really the place for this discussion, but I was hoping since the OP and others here were familiar with obtaining the setting, they may have been involved with projects that might have had similar experiences as mine.

Link to comment
Share on other sites

14 minutes ago, ModemJunki said:

I think this would be hardware specific. Not all systems have an UEFI shell in their firmware.

As I wrote my previous response a light bulb went off in my head. I think I am now on the right path to fixing my issue (and solve the mystery why I may have lost UEFI):

Quote

Prior to the Windows 10 Creators Update, in order to enable UEFI this would require a wipe and reinstall. This is because Microsoft Windows requires GUID Partition Table (GPT) disk partitioning when booting in UEFI mode, where as Master Boot Record (MBR) is required when booting in BIOS mode. Previously there is no Microsoft-supported solution to perform a non-destructive conversion to GPT.

With the Windows 10 Creators Update, we are releasing a tool called MBR2GPT.

Quote

😁

 

Link to comment
Share on other sites

1 hour ago, coffeeturtle said:

As I wrote my previous response a light bulb went off in my head. I think I am now on the right path to fixing my issue (and solve the mystery why I may have lost UEFI):

 

You must not have BitLocker encryption on the disk -> but I have done this very conversion to several machines in the past. Have a look here for detailed how-to:

https://www.tenforums.com/tutorials/81502-convert-windows-10-legacy-bios-uefi-without-data-loss.html

This won't give you access to the UEFI shell in your BIOS, however, if that is what you are missing.

Always carry a towel.

Link to comment
Share on other sites

20 minutes ago, ModemJunki said:

You must not have BitLocker encryption on the disk -> but I have done this very conversion to several machines in the past. Have a look here for detailed how-to:

https://www.tenforums.com/tutorials/81502-convert-windows-10-legacy-bios-uefi-without-data-loss.html

This won't give you access to the UEFI shell in your BIOS, however, if that is what you are missing.

Thank you so much!  The option to go into UEFI is there, but when I hit enter on it, it doesn't do anything. I'm guessing since the OS is on an MBR HDD as opposed to GPT. Maybe?

Link to comment
Share on other sites

25 minutes ago, coffeeturtle said:

Thank you so much!  The option to go into UEFI is there, but when I hit enter on it, it doesn't do anything. I'm guessing since the OS is on an MBR HDD as opposed to GPT. Maybe?

That seems unlikely to me. A quick test might be to unplug the machine and temporarily disconnect the hard disk - but if you have a TPM controlling Bitlocker encryption this is not a safe thing to do if you don't have a recovery key handy!

Perhaps an email to the vendor support for the system or mainboard is in order (or perhaps they have a help forum).

Always carry a towel.

Link to comment
Share on other sites

7 hours ago, coffeeturtle said:

I'm guessing since the OS is on an MBR HDD as opposed to GPT. Maybe?

GPT is a must if you ever want to use UEFI, this is one of the first things you do when planning to install UEFI-based OSes :D

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

On 10/23/2019 at 10:41 PM, TheDcoder said:

GPT is a must if you ever want to use UEFI, this is one of the first things you do when planning to install UEFI-based OSes :D

I think that @coffeeturtle is trying to access UEFI shell or settings in BIOS, but I'm not sure by the description. You don't need a HDD connected for accessing the UEFI part of firmware.

 

Always carry a towel.

Link to comment
Share on other sites

On 10/23/2019 at 4:27 PM, ModemJunki said:

That seems unlikely to me. A quick test might be to unplug the machine and temporarily disconnect the hard disk - but if you have a TPM controlling Bitlocker encryption this is not a safe thing to do if you don't have a recovery key handy!

Perhaps an email to the vendor support for the system or mainboard is in order (or perhaps they have a help forum).

Thanks. It used to work though. I think it was my fault when I was cloning the drive to use an SSD. I must have reverted the drive to MBR instead of GPT. Even if this isn't the issue, I think I would like to have the drive back as a GPT drive anyway...and hopefully I can use UEFI again as well-icing on the cake.

Since we last talked, I went ahead and cloned the SSD to an HDD I still had as a backup and precaution before attempting anything. Won't have much time this weekend, but I can update you to how it goes using your instructions if I get anything done.

Link to comment
Share on other sites

15 hours ago, ModemJunki said:

I think that @coffeeturtle is trying to access UEFI shell or settings in BIOS, but I'm not sure by the description. You don't need a HDD connected for accessing the UEFI part of firmware. 

Oh, I see. In that case ignore my comments about requirement for GPT (it is only valid when you want to install an OS in UEFI mode).

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

20 hours ago, TheDcoder said:

Oh, I see. In that case ignore my comments about requirement for GPT (it is only valid when you want to install an OS in UEFI mode).

GPT conversion is a go!

On 10/25/2019 at 10:28 AM, ModemJunki said:

That is very wise. 🙂 Good luck with the task!

Thank you. The mbr2gpt /convert /allowfullOS  command worked without a hitch and more smoothly than I anticipated. The drive is now listed as GPT and my BIOS Mode = UEFI.

There are some other things I have to check out, but all is good! Thank you again!

Link to comment
Share on other sites

@coffeeturtle Very nice. Back when I did it, MBR2GPT did not exist... so I had to go the old route and back up all my important files (I did not have a spare drive back then) and then totally reformat the drive to GPT :(

If I had known better, I would have been using GPT from the start!

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • 1 year later...

Glad this isn't in a support category so I don't feel so bad necroing but since this the top result for autoit uefi...

EnvGet("firmware_type")

Works

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...