Is there any command line tool that can show (echo) Drive Letter of First Partition of any selected Multi-Partitioned Fixed Disk Drive ?
Please help me...
Best Answer Wonko the Sane , 05 April 2017 - 05:51 AM
As seen in the previously given zdrivesOR.cmd, essentially the whole thing fits in a oneliner, here is to make it easier to follow with added the provision by niemtim007 to input a Disk #:
@echo off setlocal set mydisk= set /P mydisk= Disk Number [ ? ] = ::All Lines FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ') DO ECHO %%A %%B ::Just the drive letter FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #0"') DO ECHO %%B
Wonko
Go to the full postPosted 04 April 2017 - 10:52 AM
Is there any command line tool that can show (echo) Drive Letter of First Partition of any selected Multi-Partitioned Fixed Disk Drive ?
Please help me...
Posted 04 April 2017 - 12:31 PM
I don't know how to ask but I want a command line tool which will echo Drive Letter [ L: ] if I choose Disk Drive 3 for following Fixed USB Drive.
I mean for below USB Drive if I give
INPUT - Disk 3, PARTITION 1, Batch file should give OUTPUT = DRIVE LETTER [L:]
Regards...
Posted 04 April 2017 - 01:35 PM
WMIC command is probably what you are looking for.
You will need to do the parsing thus.
WMIC Path Win32_LogicalDiskToPartition Get Antecedent^,Dependent /Format:list
You can filter with the where clause.
Posted 04 April 2017 - 06:11 PM
Here:
http://reboot.pro/to...st-and-ddlistw/
the stupid board software botched codeboxes, get the actual batch from here:
http://reboot.pro/to...listw/?p=173100
and some more here:
http://reboot.pro/to...command-prompt/
BUT now that Nirsoft's Driveletterview:
http://www.nirsoft.n...etter_view.html
can be piped from console, it is probably the easiest tool to use, *like*:
@ECHO OFF ( ECHO [General] ECHO Columns=64 00 00 00 00 00 01 00 96 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 FA 00 03 00 92 00 02 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00 0B 00 00 00 0C 00 00 00 0D 00 00 00 0E 00 00 00 0F 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 13 00 00 00 14 00 ECHO Sort=7 )>DriveLetterView.cfg DriveLetterView.exe /stab ""|FIND "Phy" PAUSE
Wonko
Posted 04 April 2017 - 06:53 PM
Yeh, Erwan.l is correct, but that's gonna be nasty for loop, heh.
Posted 04 April 2017 - 07:20 PM
Nothing particularly "nasty", an example batch using ONLY WMIC is on the given thread, here:
http://reboot.pro/to...rompt/?p=189688
and in a clear version here:
http://reboot.pro/to...rompt/?p=189698
as said there:
Well, it was just some fun.
the "clear" batch is not really a batch, it is just a bunch of lines, three for loops, only to show how for simple things a simple batch can compete with the much more complex .vbs script (winning hands down when it comes to go through Ockham's Razor, or more plainly using the KISS principle).
it's just three FOR loops.
Wonko
Posted 04 April 2017 - 09:14 PM
First thanks for providing great batch file...Sorry but I am unable to understand functioning of variables used within batch file...
Blueprint of what I am trying to do is-
SET USBDRIVELETTER= SET %%B=3 SET %%D=0 CALL mydrivesOR.cmd SET USBDRIVELETTER=%%E echo USB Drive Letter %USBDRIVELETTER% is connected.
Posted 05 April 2017 - 12:53 AM
variables as you suggest above comes from FOR LOOP DO. if FOR LOOP defines %%A for example as start %%A is token 1 %%B token 2 and so on.
As for the loop needed to use WMIC you would basically query/ask class in WMI and section and compare those inside for loop to next class using another for loop or if statement to query/ask the match and when found add that as variable.
For the nasty part... Some of WMIC query compare escapes there are really nasty actually specially the " while capturing Win32_LogicalDiskToPartition is quite some tour to cmd basics, heh.
Posted 05 April 2017 - 03:22 AM
Maybe this will help you
@echo off setlocal mode con lines=10 cols=75 :select set disk= set /P disk= Disk Number [ ? ] = rem check External Portable Hard Drives wmic diskdrive get Name, Model, InterfaceType, MediaType | find /i "\\.\PHYSICALDRIVE%disk%" | find /i "Fixed hard disk media" >nul if errorlevel 1 goto :continue color 4f& echo.& echo Invalid Input.& pause>nul& cls& goto :select :continue rem the first partition is 0 set partition=0 for /f "tokens=3 delims==" %%b in ( 'WMIC Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent ^| find "Disk #%disk%, Partition #%partition%"' ) do set letter=%%b set letter=%letter:~1,2% echo The letter of the disk %disk%, partition %partition% is %letter% pause>nul endlocal exit
Posted 05 April 2017 - 04:06 AM
First lots of thanks for developing feature rich 'MultiBoot_Toolkit_2.1.0'.
Another thanks for writing above codes for me....It's give me exactly what I was looking for....
Thanks & Regards...
Posted 05 April 2017 - 05:51 AM Best Answer
As seen in the previously given zdrivesOR.cmd, essentially the whole thing fits in a oneliner, here is to make it easier to follow with added the provision by niemtim007 to input a Disk #:
@echo off setlocal set mydisk= set /P mydisk= Disk Number [ ? ] = ::All Lines FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ') DO ECHO %%A %%B ::Just the drive letter FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #0"') DO ECHO %%B
Wonko
Posted 05 April 2017 - 10:40 AM
Maybe this will help you
D4mn, that's nice looking. I tested looping thru all I mentioned above and was like 4 loops. Wonder what will that do if the CD/DVD/BD drive is before removable or there's more than 1 removable media.
Then again it's still very very nice example how to dig up that info with 1 loop.
Posted 05 April 2017 - 02:18 PM
@echo off setlocal rmpartusb% LIST | find "DRIVE" set DD= set /P DD=Please enter your lucky number: set /a DD=DD if "%DD%"=="" goto :end if "%DD%"=="0" goto :end set mydisk=%DD% set USBDRIVELETTER= FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #0"') DO set USBDRIVELETTER=%%B ECHO %USBDRIVELETTER% & PAUSE
BTW, Is there any simple way to get if connected USB Disk Drive is "Removable" or "Fixed' ?
If USB Drive is "Removable", then I will use
FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #0"') DO set USBDRIVELETTER=%%B
If USB Drive is "Fixed", then I will use
FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #1"') DO set USBDRIVELETTER=%%B OR FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #2"') DO set USBDRIVELETTER=%%B
How can I do this in above batch file ?
Thanks for providing all your support and help....
Regards...
Posted 05 April 2017 - 09:16 PM
Well, I honestly would say this whole post started a bit wrong as you can't just assume that there is 1 External USB connected media in system and you cannot assume there is no Removable USB connected media in system or how many of both there are. None of examples here gives that information, none of it checks if it's active or not as, if any of above examples would break at "External hard disk media" where USB would of course start with "Removable media ..." where again floppy drives would bug out.
Ideally loop should start something similar to this:
setlocal enabledelayexpansion set /a "_EXTERNAL_COUNT=0" set /a "_REMOVABLE_COUNT=0" FOR /F "skip=1" %%a IN ('WMIC DiskDrive get MediaType,DeviceID,Partitions') DO ( IF [%%B]==[External] ( set /a "_EXTERNAL_COUNT+=1" set "_ExtMedia_!_EXTERNAL_COUNT! = %%%a:~-1%" rem set "_ExtMedia_!_EXTERNAL_COUNT!_Partitions = %%E" ) IF [%%B]==[Removable] ( set /a "_REMOVABLE_COUNT+=1" set "_RemMedia_!_REMOVABLE_COUNT! = %%%a:~-1%" rem set "_RemMedia_!_REMOVABLE_COUNT!_Partitions = %%F" ) endlocal
NOTE: That Partitions variable is still wrong.
The point there is that basically would count how many External Fixed Drives there is how many Removable, include Drive number they are located and that would need to be matched like @Wonko example looping thru both unless _########_COUNT=0 and those Drives should be matched to WMIC VOLUME Bootable,Caption to verify that, if ex. External Disk #0 Partition #1 -> Drive letter<->Caption/Name is not flagged bootable=true then that partition is not the first partition shown while booted from.
Anyway, as I said I did try to write it and took 4 loops total and it still does, if done right, but assuming above examples are enough for project you are working with.
Posted 05 April 2017 - 10:52 PM
@ genetix
There is no need to assume anything, he is sure there will be only one USB connected, because he (the user) is in front of the PC and he will connect just one USB with his tools. So there is no need to over complicate the batch my friend.
alacran
Posted 05 April 2017 - 11:23 PM
Is there any simple way to get if connected USB Disk Drive is "Removable" or "Fixed' ?
There is the code I use in my own Multiboot Toolkit, maybe this will help you!?
rem --> check USB disk wmic diskdrive get Name, Model, InterfaceType, MediaType | find /i "removable Media" | find /i "\\.\PHYSICALDRIVE%disk%" >nul if not errorlevel 1 goto :removable rem --> check HDD box wmic diskdrive get Name, Model, InterfaceType, MediaType | find /i "External hard disk media" | find /i "\\.\PHYSICALDRIVE%disk%" >nul if not errorlevel 1 goto :Fixed :removable rem --> put your code here :Fixed rem --> put your code here
Posted 05 April 2017 - 11:32 PM
Finally I have just added following code in my 'SMART_USB.cmd'. Thanks 'Wonko' for providing single line logic for getting driver letter of Partition 1 of any Disk....@echo off setlocal rmpartusb% LIST | find "DRIVE" set DD= set /P DD=Please enter Disk number: set /a DD=DD if "%DD%"=="" goto :end if "%DD%"=="0" goto :end set mydisk=%DD% set USBDRIVELETTER= FOR /F delims^=\^"^ tokens^=5^,11 %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get /Format:csv ^|FIND "Disk #%mydisk%, Partition #0"') DO set USBDRIVELETTER=%%B ECHO %USBDRIVELETTER% & PAUSE
I first list ALL External USB Drive (both Removable and Fixed) using 'RMPARTUSB.exe'. And then choose disk number "%DD%" which I want to made 'SMART_USB'. So here there is no need to assume anything. I am choosing desired USB Drive manually in my batch file...
BTW, Thanks for providing your approcach....
Regards..
Posted 06 April 2017 - 08:53 AM
@alacran
Usually writing a batch is 15% writing the batch and the other 150% is finding ways to prevent the user from doing something he/she shouldn't.
Of course for "internal" use it is fine , but, just as an example, validating that the input given is actually a number (and a single one) would prevent a number of possible mistypings:
@echo off setlocal enableextensions :loop SET /p Number=Please type a number 0-9: ::check that they are only digits FOR /F "tokens=1 delims=0123456789" %%A IN ("%Number%") DO ECHO Oh,oh, not a single number&PAUSE&GOTO :loop ::and get only first digit SET Number=%Number:~0,1% ECHO OK, number is %Number%
Wonko
Posted 06 April 2017 - 09:11 AM
@ genetix
There is no need to assume anything, he is sure there will be only one USB connected, because he (the user) is in front of the PC and he will connect just one USB with his tools. So there is no need to over complicate the batch my friend.
alacran
Yeah, I've just for past 5-15 years been mostly building something which is specifically compatible to some "unique scenario". It just has always been a bad idea. Which is why I am so much against creating something that is "just supporting that unique system..." and waste of time, but instead would support all scenarios, so, it can be reused by anyone, if I would of figured to do a bit extra work like between years 2000-2015, I wouldn't be writing the code currently as I am now, but instead I could be creating something new to improve it.
Groups →
Windows Extreme →
Windows 10 →
Driverstore RepositoryStarted by antonino61 , 19 May 2023 windows 10, windows 11 |
|
|
||
Groups →
Windows Extreme →
Windows 7 →
How can I dual boot Windows 10 and Windows 7 on a Surface Book 2?Started by nar , 30 Jul 2020 windows 10, windows 7, dual boot |
|
|
||
bsod
Groups →
Windows Extreme →
Windows 10 →
BSOD Crashes Windows 10 since May UpdateStarted by wimb , 07 Jun 2020 bsod, crash, update, windows 10 |
|
|
||
Boot methods & tools →
Boot from LAN →
RFI - Widnows 10 Iscsi sysprep.Started by moriarty , 06 May 2020 ipxe, iscsi, windows 10, sysprep and 1 more... |
|
|
||
Boot methods & tools →
Boot from USB / Boot anywhere →
USB-Stick mounted as Fixed Or as RemovableStarted by wimb , 07 Aug 2019 usb, fixed, removable, windows 10 |
|
|
0 members, 0 guests, 0 anonymous users