Check if drive UUID exists from batch file

User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
Post Reply
YesAndNo
Posts: 44
Joined: Sat Aug 24, 2013 11:14 am

Check if drive UUID exists from batch file

Post 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.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: Check if drive UUID exists from batch file

Post 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
YesAndNo
Posts: 44
Joined: Sat Aug 24, 2013 11:14 am

Re: Check if drive UUID exists from batch file

Post 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.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: Check if drive UUID exists from batch file

Post 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?
YesAndNo
Posts: 44
Joined: Sat Aug 24, 2013 11:14 am

Re: Check if drive UUID exists from batch file

Post 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.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: Check if drive UUID exists from batch file

Post 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...)
Last edited by Eric on Tue Sep 03, 2019 8:56 am, edited 1 time in total.
YesAndNo
Posts: 44
Joined: Sat Aug 24, 2013 11:14 am

Re: Check if drive UUID exists from batch file

Post 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.
TeraByte Support(PP)
Posts: 1643
Joined: Fri Aug 12, 2011 12:51 am

Re: Check if drive UUID exists from batch file

Post 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.
YesAndNo
Posts: 44
Joined: Sat Aug 24, 2013 11:14 am

Re: Check if drive UUID exists from batch file

Post 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.
Post Reply