User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
Wed Aug 28, 2019 1:01 pm
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.
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:
for hd=0 to 63
if h and (h.sig=diskid or h.guid=diskid) then
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.
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?
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:
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%" (
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.
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.
Sat Aug 31, 2019 1:36 am
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
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.
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.
Any other ideas welcome.
phpBB® Forum Software © phpBB Group.
phpBB Mobile by Artodia.