Page 1 of 1

Check if drive UUID exists from batch file

PostPosted: Wed Aug 28, 2019 1:01 pm
by YesAndNo
Hello,
Quick question: Can I determine if a particular disk is present by checking the disk ID or similar in a batch script from WinPE so I can do an if/else statement to automate things a bit more? Using same backup drive with more than one PC is the reason. Using Tom Cole's scripts as well if that helps.

Will give more info if needed, but hopefully it makes sense.
Thanks for any help.

Re: Check if drive UUID exists from batch file

PostPosted: Wed Aug 28, 2019 11:02 pm
by Eric
Yes, with a TBOSDT script you can do that. You have to build a loop, read disk one by one, until the one found.
The script can have as entry the disk id (signature or Guid), and can return the disk number (-1 if not found). Like this:
sub main()
diskid=arg(1)
hdnum=-1
for hd=0 to 63
h=GetHdInfo(hd)
if h and (h.sig=diskid or h.guid=diskid) then
hdnum=h.num
ExitLoop
end if
next
return hdnum
end sub

Re: Check if drive UUID exists from batch file

PostPosted: Fri Aug 30, 2019 4:55 am
by YesAndNo
Thanks Eric, never looked at TBOSDT. Will look into it but would prefer a native windows commands if it's possible.

Thanks again.

Re: Check if drive UUID exists from batch file

PostPosted: Fri Aug 30, 2019 5:13 am
by Eric
You would call that script directly through a command line (with admin rights, like this "tbosdtw.exe script.tbs 12345678"), and you would get the result in the ErrorLevel DOS variable (if -1, no hd found, otherwise number of the hd found).

But maybe you can use diskpart to do that?

Re: Check if drive UUID exists from batch file

PostPosted: Fri Aug 30, 2019 2:01 pm
by YesAndNo
Thanks again Eric.
After some searching online I found a couple of examples that led me to this and it seems to work at least in Windows 7:

@echo off
set test=1234-5678

for %%i in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
if exist %%i:\ (
for /f "tokens=5 delims= " %%j in ('vol %%i: ^| find "Serial Number"') do (
rem echo %%i
if "%%j" == "%test%" (
echo %%j
)
)
)
)

I'm very rusty on this now but it works on Windows 7, haven't tried in WinPE.

Is the serial that "vol" returns set into the drive or is it some number assigned by Windows?
If there's any problems with this code please let me know.
Thanks for any help.

Re: Check if drive UUID exists from batch file

PostPosted: Sat Aug 31, 2019 12:07 am
by Eric
À volume serial number is linked to the volume (so the partition), not the disk itself. So linked to the drive letter.
It depends what you have as entry, and what you need at the end.
IFW can accept disk id as entry for backup (so you can say I want to backup the disk which id is...)

Re: Check if drive UUID exists from batch file

PostPosted: Sat Aug 31, 2019 1:36 am
by YesAndNo
Thanks Eric.
Yes, I've now realised that volume ID is not what I'm after.

There is a "wmic" command in Windows 7 that returns serial number for each drive on a separate line. Not sure yet how to pass each line though.

Reason for all this is to load a custom command-line menu depending on what machine I'm running TBWinPE on (or rather, what drive it finds there).

By the way, I have to mention that I did simplify part of the previous code, no need to use "find":

for /f "skip=1 tokens=5" %%j in ('vol %%i:') do (
rem do something here with %%j
)

Thanks again.

Re: Check if drive UUID exists from batch file

PostPosted: Sat Aug 31, 2019 8:47 am
by TeraByte Support(PP)
If you don't need the ID for some reason, an alternative would be to search for a specific file on the drive instead. The filename and location could be whatever you want to distinguish the drive.

Re: Check if drive UUID exists from batch file

PostPosted: Mon Sep 09, 2019 1:15 pm
by YesAndNo
Sorry I didn't reply sooner,
Problem there is that one system is Linux and, as far as I'm aware, Windows cannot read the ext4 file system.
Thanks though.

Any other ideas welcome.