user1128144
user1128144

Reputation: 125

How to detect if EFI partition is already mounted in Windows via batch script?

I'm trying to write a batch script to detect if an EFI partition is already mounted in Windows.

Ultimately, my goal is to use mountvol /S (mount EFI system partition) only if the EFI partition is not already mounted.

The diskpart utility with the list volume command has some potentially helpful information as does mountvol by itself, but it looks like both of these will require some string parsing.

Is there a better way?

Upvotes: 3

Views: 5612

Answers (2)

S At
S At

Reputation: 467

For mount EFI partition in Windows eg. Win10. Change ur account to Administrator and right click on the window sign(on the left side) and select "Command Prompt(Admin)" then write 'diskpart' then 'select disk 1'(or '0' try it) then 'select partition 1' then 'assign letter=b' and YUP ;).

Upvotes: 1

iesou
iesou

Reputation: 706

I'm not sure there is any easier way... but the parsing isn't that big of a deal. Here is something that should do what you need:

@echo off
setlocal enabledelayedexpansion
echo list volume > listvol.tmp

REM Checks for "efisys" in the list volume function. If it finds it, checks status. If not healthy sets var to No
for /F "tokens=6-9 delims= " %%G IN ('diskpart /s listvol.tmp') DO IF /I %%G==efisys set mounted=%%J

if '%mounted%'=='Healthy' set mounted=Yes
if not '%mounted%'=='Yes' set mounted=No

echo Is EFI drive mounted?
echo %mounted%.
pause

del listvol.tmp
endlocal

Edited because I was parsing for wrong value.

Upvotes: 5

Related Questions