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.

Check if drive UUID exists from batch file

Postby YesAndNo » Wed Aug 28, 2019 1:01 pm

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

Re: Check if drive UUID exists from batch file

Postby Eric » Wed Aug 28, 2019 11:02 pm

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
Eric
 
Posts: 167
Joined: Mon Sep 05, 2011 11:53 am
Location: France

Re: Check if drive UUID exists from batch file

Postby YesAndNo » Fri Aug 30, 2019 4:55 am

Thanks Eric, never looked at TBOSDT. Will look into it but would prefer a native windows commands if it's possible.

Thanks again.
YesAndNo
 
Posts: 30
Joined: Sat Aug 24, 2013 4:14 am

Re: Check if drive UUID exists from batch file

Postby Eric » Fri Aug 30, 2019 5:13 am

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?
Eric
 
Posts: 167
Joined: Mon Sep 05, 2011 11:53 am
Location: France

Re: Check if drive UUID exists from batch file

Postby YesAndNo » Fri Aug 30, 2019 2:01 pm

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

Re: Check if drive UUID exists from batch file

Postby Eric » Sat Aug 31, 2019 12:07 am

À 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 1:56 am, edited 1 time in total.
Eric
 
Posts: 167
Joined: Mon Sep 05, 2011 11:53 am
Location: France

Re: Check if drive UUID exists from batch file

Postby YesAndNo » Sat Aug 31, 2019 1:36 am

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

Re: Check if drive UUID exists from batch file

Postby TeraByte Support(PP) » Sat Aug 31, 2019 8:47 am

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.
Paul Purviance
TeraByte Support
TeraByte Support(PP)
 
Posts: 1332
Joined: Thu Aug 11, 2011 5:51 pm

Re: Check if drive UUID exists from batch file

Postby YesAndNo » Mon Sep 09, 2019 1:15 pm

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


Return to Scripting