victor888

[Updated on Feb. 27. 2011] ordering messed drive letter batch file

58 posts in this topic

test again on another pc

result without /v switch

C: 0,0 IDE	  Fixed
D: 0,1 IDE Fixed
E: 0,2 IDE Fixed
F: 0,3 IDE Fixed
G: 0,4 IDE Fixed
H: IDE CD-ROM
I: 2,0 USB Removable
J: Fixed
K: Fixed
M: Fixed

Same result as previous test. J,K,L are usb hard disk drive letters, no USB type found.

result with /v switch

PHN=2,0
Ph_Drive_Bus_0=IDE
Ph_Drive_Bus_1=USB
Ph_Drive_Bus_2=USB
PH_drive_Letter_0_0=C:
PH_drive_Letter_0_1=D:
PH_drive_Letter_0_2=E:
PH_drive_Letter_0_3=F:
PH_drive_Letter_0_4=G:
PH_drive_Letter_2_0=I:
Ph_drive_PIP_2="7&21572299&0"
Ph_drive_Sig_0=ca2319a4
Ph_Drive_Type_0=Fixed
Ph_Drive_Type_1=Fixed
Ph_Drive_Type_2=Removable
Drive_Bus_H=IDE
Drive_Data=000000005C005C003F005C00530054004F005200410047004500230056006F006C007
5006D006500230031002600330030006100390036003500390038002600300026005300690067006
E0061007400750072006500320031003900450030004600430043004F00660066007300650074003
900340037003500350044003800300030004C0065006E00670074006800430034003100330034003
000300023007B00350033006600350036003300300064002D0062003600620066002D00310031006
40030002D0039003400660032002D003000300061003000630039003100650066006200380062007
D0000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000005C005C003F005C0056006F006C0075006D0065007B0036003400620032003
1006400620065002D0062006600350037002D0031003100640064002D0039003200340033002D003
000300031003300320030003500370039003100340031007D005C0
Drive_Letter_C=C
Drive_Letter_D=D
Drive_Letter_E=E
Drive_Letter_F=F
Drive_Letter_G=G
Drive_Letter_H=H
Drive_Letter_I=I
Drive_Letter_J=J
Drive_Letter_K=K
Drive_Letter_M=M
Drive_REF_C={317bb1be-bc5b-11dd-8642-806d6172696f}
Drive_REF_D={317bb1bf-bc5b-11dd-8642-806d6172696f}
Drive_REF_E={317bb1c0-bc5b-11dd-8642-806d6172696f}
Drive_REF_F={317bb1c1-bc5b-11dd-8642-806d6172696f}
Drive_REF_G={317bb1c2-bc5b-11dd-8642-806d6172696f}
Drive_REF_H={2a4fb5f2-bf44-11dd-9240-806d6172696f}
Drive_REF_I={5199df13-c010-11dd-9247-001320579141}
Drive_REF_J={64b21dbc-bf57-11dd-9243-001320579141}
Drive_REF_K={64b21dbd-bf57-11dd-9243-001320579141}
Drive_REF_M={64b21dbe-bf57-11dd-9243-001320579141}
Drive_Sig_C=ca2319a4
Drive_Sig_D=ca2319a4
Drive_Sig_E=ca2319a4
Drive_Sig_F=ca2319a4
Drive_Sig_G=ca2319a4
Drive_Sig_J=219e0fcc
Drive_Sig_K=219e0fcc
Drive_Sig_M=219e0fcc
Drive_Type_C=Fixed
Drive_Type_D=Fixed
Drive_Type_E=Fixed
Drive_Type_F=Fixed
Drive_Type_G=Fixed
Drive_Type_H=CD-ROM
Drive_Type_I=Removable
Drive_Type_J=Fixed
Drive_Type_K=Fixed
Drive_Type_M=Fixed

I have to point out, in order to have a good speed, use as less REQ QUERY in the FOR circle as possible.

I am still checking your code.

0

Share this post


Link to post
Share on other sites

@Victor888

I know you'll simply LOVE this snippet:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
GOTO :Start
::THIS IS LINE #5 in this batch
select disk 0
detail disk
EXIT
::THIS IS LINE #9 in this batch
select disk 1
detail disk
EXIT
::THIS IS LINE #13 in this batch
select disk 2
detail disk
EXIT
::THIS IS LINE #17 in this batch
select disk 3
detail disk
EXIT
::THIS IS LINE #21 in this batch
select disk 4
detail disk
EXIT
::THIS IS LINE #25 in this batch
select disk 5
detail disk
EXIT
::THIS IS LINE #29 in this batch
select disk 6
detail disk
EXIT

:Start
FOR /F "tokens=2,7" %%A IN ('ECHO list disk^|diskpart^|FIND "B"') DO SET DP_disks=!DP_disks! %%A
FOR %%A IN (%DP_disks%) DO (
SET /A DP_Line#=%%A*4+5
FOR /F "skip=8 tokens=1,2,3 delims=: " %%B IN ('MORE +!DP_Line#! %~dpnx0^|diskpart.exe^|FIND /v /i "DISKPART"') DO (
ECHO working....
ECHO ....
ECHO %%B %%C %%D
IF %%B.==Disk. SET DP_disk_sig_%%A=%%D
IF %%B.==Volume. IF NOT %%C.==n.. SET DP_disk_letters_%%A=!DP_disk_letters_%%A! %%D
IF %%B.==Type. SET DP_disk_bus_%%A=%%C
)
)
CLS&SET DP_disk
GOTO :EOF

;)

jaclaz

0

Share this post


Link to post
Share on other sites

Dizzy.

I study registry enough, that I wrote a paper about registry searching in Chinese.

I have no time to translate.

http://bbs.wuyou.com/viewthread.php?tid=13...;extra=page%3D2

In fact to detemine the signature belongs to which disk if more than one hard disk installed there is a better way:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\STORAGE\Volume\1&30a96598&0&SignatureA8E1B9D2Offset7E00LengthXXXXXXXX

The key "driver",{71A27CDD-812A-11D0-BEC7-08002BE2092F}\0022,the last two number "22" tells the disk number. That is the driver value of disk 0 is smaller than that of disk 1, the latter is smaller than that of disk 2, etc.

Under pe, no driver key exist.

0

Share this post


Link to post
Share on other sites

A bettered snippet, that allows to put the diskpart batch commands at the end of the file, indexing them automatically and making it run much faster:


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=1 delims=[]" %%A in ('FIND /N "::THIS IS START OF DISKPART BATCH COMMANDS::" %~dpnx0') DO SET More_offset=%%A
FOR /F "tokens=2,7" %%A IN ('ECHO list disk^|diskpart^|FIND "B"') DO SET DP_disks=!DP_disks! %%A
FOR %%A IN (%DP_disks%) DO (
SET /A DP_Line#=%%A*3+%More_offset%
FOR /F "skip=8 tokens=1,2,3 delims=: " %%B IN ('MORE +!DP_Line#! %~dpnx0^|diskpart.exe^|FIND /v /i "DISKPART"') DO (
IF %%B.==Disk. SET DP_disk_sig_%%A=%%D
IF %%B.==Volume. IF NOT %%C.==n.. IF NOT %%D.==Ltr. SET DP_disk_letters_%%A=!DP_disk_letters_%%A! %%D
IF %%B.==Type. SET DP_disk_bus_%%A=%%C
)
)
SET DP_disk
GOTO :EOF

::THIS IS START OF DISKPART BATCH COMMANDS::
select disk 0
detail disk
EXIT
select disk 1
detail disk
EXIT
select disk 2
detail disk
EXIT
select disk 3
detail disk
EXIT
select disk 4
detail disk
EXIT
select disk 5
detail disk
EXIT
select disk 6
detail disk
EXIT

Cheers,

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Very good example though it is language related.

I use English mountvol.exe to test it.

The result is very very good.

Edited by victor888
0

Share this post


Link to post
Share on other sites

Yep, I tested it in English and Italian.

The only "localized" part should be :unsure::

IF %%B.==Disk. SET DP_disk_sig_%%A=%%D

IF %%B.==Volume. IF NOT %%C.==n.. IF NOT %%D.==Ltr. SET DP_disk_letters_%%A=!DP_disk_letters_%%A! %%D

IF %%B.==Type. SET DP_disk_bus_%%A=%%C

If users of other languages would post the corresponding for:

Disk

Volume

n.

Type

it should be possible to "widen the intended audience"....;)

jaclaz

P.S.: Edit changed line to allow Italian and English

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Your idea of use batch file itself as diskpart script is wonderful.

By the way has to point out, for vista, removable usb disk is also detected in diskpart.

0

Share this post


Link to post
Share on other sites
If users of other languages would post the corresponding for:

Disk

Volume

n.

Type

it should be possible to "widen the intended audience"....;)

From where do i get these informations? Can post them for a handful of languages.

Thank for the script! I tested it and found a tiny bug. If the path to the file contains a space the script breaks up. Just place "" around %~dpnx0

0

Share this post


Link to post
Share on other sites
From where do i get these informations? Can post them for a handful of languages.

Thank for the script! I tested it and found a tiny bug. If the path to the file contains a space the script breaks up. Just place "" around %~dpnx0

Thanks for the reminder about the quotes: I am so used to use the "right" ;) naming convention of paths without spaces that I always forget about other users habits. :blushing:

Maybe there is no need to make a multilingual check, try this version - where I tried to use actual "places" on lines to get the info.


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=1 delims=[]" %%A in ('FIND /N "::THIS IS START OF DISKPART BATCH COMMANDS::" "%~dpnx0"') DO SET More_offset=%%A

FOR /F "tokens=*" %%A IN ('ECHO list volume^|diskpart^|FIND "Vol"^|FIND "B"') DO (
SET LINE=%%A
SET token1=!LINE:~7,2!
SET token1=!token1: =!
IF !token1! lss 10 SET token1=0!token1!
SET token2=!LINE:~13,1!
SET DP_Vol#!token1!=!token2!
)

SET DP


FOR /F "tokens=2,7" %%A IN ('ECHO list disk^|diskpart^|FIND "B"') DO SET DP_disks=!DP_disks! %%A


FOR %%A IN (%DP_disks%) DO (
SET /A DP_Line#=%%A*3+%More_offset%
SET /A Counter=0
FOR /F "skip=8 tokens=* delims=" %%B IN ('MORE +!DP_Line#! "%~dpnx0"^|diskpart.exe^|FIND /v /i "DISKPART"') DO (
Set /A Counter+=1
IF !Counter!==1 CALL :Parse_Line DP_disk_sig_%%A %%B
IF !Counter!==2 CALL :Parse_Line DP_disk_bus_%%A %%B
IF !Counter! GTR 7 CALL :Parse_Line DP_disk_letters_%%A %%B
)
)

FOR /F "tokens=2* delims==" %%A IN ('SET DP_disk_letters_') DO SET DP_disk_letters=!DP_disk_letters! %%A
SET DP_disk_letters=!DP_disk_letters: = !
SET DP_disk


SET ALLDRIVES=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
SET BUSYDRV=
SET FREEDRV=
ECHO.
:: List drive letters for physical drives
FOR /F "tokens=1 delims=\ " %%A IN ('MOUNTVOL /L ^| SORT ^| FIND ":\"') DO SET BUSYDRV=!BUSYDRV! %%A
:: List drive letters for network drives
FOR /F "tokens=*" %%A IN ('NET USE ^|FIND ":"') DO (
SET This_Drive=%%A
SET This_Drive=!This_Drive:~13,1!
SET BUSYDRV=!BUSYDRV! !This_Drive!
SET NETDRV=!NETDRV! !This_Drive!
)
SET BUSYDRV=%BUSYDRV::=%

:: Check which drive letters aren't used and list them as free driveletters
FOR %%A IN (%ALLDRIVES%) DO (
ECHO.%BUSYDRV% | FIND "%%A">nul
IF ERRORLEVEL 1 (SET FREEDRV=!FREEDRV! %%A:&ECHO %%A: FREE) ELSE (ECHO %%A: BUSY)
)
:: Remove leading comma
SET FREEDRV=%FREEDRV::=%

FOR /F "skip=1 tokens=1 delims= " %%A in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum /s ^|find "\"') do (
SET ALLDisks=!ALLdisks! %%A
)

FOR %%A IN (%ALLDISKS%) DO (
ECHO.%DP_disks% | FIND " %%A ">nul
IF ERRORLEVEL 1 SET NOT_DP_Disks=!NOT_DP_Disks! %%A
)

FOR %%A IN (%BUSYDRV%) DO (
ECHO.%DP_disk_letters% | FIND " %%A ">nul
IF ERRORLEVEL 1 SET NOT_DP_Drives=!NOT_DP_Drives! %%A
)

SET NOT_
SET BUSY
SET FREE
SET NET
GOTO :EOF

:Parse_line
SET %1=!%1! %4
GOTO :EOF

::THIS IS START OF DISKPART BATCH COMMANDS::
select disk 0
detail disk
EXIT
select disk 1
detail disk
EXIT
select disk 2
detail disk
EXIT
select disk 3
detail disk
EXIT
select disk 4
detail disk
EXIT
select disk 5
detail disk
EXIT
select disk 6
detail disk
EXIT

0

Share this post


Link to post
Share on other sites

Checking the "mbrfix" version.

Something is simply NOT right.

Preliminary:

the "EXIT" in the first few lines is not a good idea (for people that run the batch from Command Prompt)

first part of the output:

All drive letters:  C D M N O P Q R Y
Mounted drive letters: C D M N O P Q R
Virtual drive letters: Y
Internal hard disk 1 drive letter: C
Internal hard disk 2 drive letter: D
Internal hard disk 3 drive letter: {80cf88c6-8a34-11dd-813c-806d6172696f}R {80c
f88c6-8a34-11dd-813c-806d6172696f}R {80cf88c6-8a34-11dd-813c-806d6172696f}R {80c
f88c6-8a34-11dd-813c-806d6172696f}R {80cf88c6-8a34-11dd-813c-806d6172696f}R {80c
f88c6-8a34-11dd-813c-806d6172696f}R {80cf88c6-8a34-11dd-813c-806d6172696f}R {80c
f88c6-8a34-11dd-813c-806d6172696f}R {80cf88c6-8a34-11dd-813c-806d6172696f}R
Cd/dvd rom drive letters: M
Removalbe drive letters: N O P Q R

A minor typo:Removalbe->Removable

the call to :vdrv creates havoc, as the %1 is "{80f886-8a34-11dd-813-806d6172696f}R"

Mounted drive letters is NOT sorted and probably cause something queer, or some variable are left after batch competion, on second run:

All drive letters:  C D E F G H I J Y
Mounted drive letters: C E D F G H I J
Virtual drive letters: Y
Internal hard disk 1 drive letter: C
Internal hard disk 2 drive letter: E
Internal hard disk 3 drive letter: {80cf88c6-8a34-11dd-813c-806d6172696f}J {80c
f88c6-8a34-11dd-813c-806d6172696f}J {80cf88c6-8a34-11dd-813c-806d6172696f}J {80c
f88c6-8a34-11dd-813c-806d6172696f}J {80cf88c6-8a34-11dd-813c-806d6172696f}J {80c
f88c6-8a34-11dd-813c-806d6172696f}J {80cf88c6-8a34-11dd-813c-806d6172696f}J {80c
f88c6-8a34-11dd-813c-806d6172696f}J {80cf88c6-8a34-11dd-813c-806d6172696f}J
Cd/dvd rom drive letters: D
Removalbe drive letters: F G H I J

In :vdrv:

:vdrv
set nk=!fulldrv:~%k%,1!
if /i %1 neq !nk! (
set ordereddrv=!ordereddrv! %1¡ú!nk!
mountvol %1: /d
set viddrv=!viddrv! !totalvid:~%e%,38!!nk!
)
goto :eof

there is something strange, what the heck is ¡ú maybe some "extended characters" of some kind?

The batch continues with a bunch of errors, too many to pinpoint at the moment, then I get this:

ORDERED DRIVE LETTERS:  {80f886-8a34-11dd-813-806d6172696f}Jí·D {80f886-8a34-11d
d-813-806d6172696f}Jí·E {80f886-8a34-11dd-813-806d6172696f}Jí·F {80f886-8a34-11d
d-813-806d6172696f}Jí·G {80f886-8a34-11dd-813-806d6172696f}Jí·H {80f886-8a34-11d
d-813-806d6172696f}Jí·I {80f886-8a34-11dd-813-806d6172696f}Jí·J {80f886-8a34-11d
d-813-806d6172696f}Jí·K {80f886-8a34-11dd-813-806d6172696f}Jí·L Eí·M Dí·N Fí·O G
í·P Hí·Q Ií·R Jí·S

and later on this:

Internal hard disk 3 drive letter:
Usb hard disk 1 drive letters: C
Usb hard disk 2 drive letters: D
Cd/dvd rom drive letters: M
Removalbe drive letters: N O P Q R

and later on this:

ORDERED DRIVE LETTERS:  Mí·D Dí·E Ní·F Oí·G Pí·H Qí·I Rí·J

The diskpart version behaves a bit better, but still NOT WORKING (as well with the EXIT REMmed out):

first run:

C:\Downloaded\md5\diskpart>orderdrv_diskpart
"orderdrv_diskpart.cmd" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.
All drive letters: C D E F G H I J Y
Mounted drive letters: C E D F G H I J
Virtual drive letters: Y
Internal hard disk 1 drive letter: C
Internal hard disk 2 drive letter: E
Internal hard disk 3 drive letter:
Cd/dvd rom drive letters: D
Removalbe drive letters: F G H I J
ORDERED DRIVE LETTERS: Eí·D Dí·E
Premere un tasto per continuare . . .
!nk! non atteso.

Second run:

C:\Downloaded\md5\diskpart>orderdrv_diskpart

"orderdrv_diskpart.cmd" non è riconosciuto come comando interno o esterno,

un programma eseguibile o un file batch.

All drive letters: C D E F G H I J Y

Mounted drive letters: C D E F G H I J

Virtual drive letters: Y

Internal hard disk 1 drive letter: C

Internal hard disk 2 drive letter: D

Internal hard disk 3 drive letter:

Cd/dvd rom drive letters: E

Removalbe drive letters: F G H I J

DIRVE LETER ORDER IS CORRECT.

Premere un tasto per continuare . . .

!nk! non atteso.

Again a small typo:

DIRVE LETER ORDER IS CORRECT ->DRIVE LETTER ORDER IS CORRECT

As a reference this is the "right" set of mounted drives on the same machine (using ddlistw.cmd):

C:\VSS>ddlistw3
Drives by drive letter:
c: 0,1 FIX \Volume{b0b284c3-8a33-11dd-8781-806d6172696f} \HarddiskVolume1
d: 1,1 FIX \Volume{b0b284c4-8a33-11dd-8781-806d6172696f} \HarddiskVolume2
e: x,x CDR \Volume{80cf88c2-8a34-11dd-813c-806d6172696f} \CdRom0
f: 2,1 REM \Volume{5d3e8800-9c1f-11dd-8148-001fc6bb76ce} \Harddisk2\DP(1)0-0+5
g: 3,1 REM \Volume{80cf88c3-8a34-11dd-813c-806d6172696f} \Harddisk3\DP(1)0-0+a
h: 4,1 REM \Volume{80cf88c4-8a34-11dd-813c-806d6172696f} \Harddisk4\DP(1)0-0+b
i: 5,1 REM \Volume{80cf88c5-8a34-11dd-813c-806d6172696f} \Harddisk5\DP(1)0-0+c
j: 6,1 REM \Volume{80cf88c6-8a34-11dd-813c-806d6172696f} \Harddisk6\DP(1)0-0+d
Premere un tasto per continuare . . .

Drives by connection:
c: 0,1 FIX \Volume{b0b284c3-8a33-11dd-8781-806d6172696f} \HarddiskVolume1
d: 1,1 FIX \Volume{b0b284c4-8a33-11dd-8781-806d6172696f} \HarddiskVolume2
f: 2,1 REM \Volume{5d3e8800-9c1f-11dd-8148-001fc6bb76ce} \Harddisk2\DP(1)0-0+5
g: 3,1 REM \Volume{80cf88c3-8a34-11dd-813c-806d6172696f} \Harddisk3\DP(1)0-0+a
h: 4,1 REM \Volume{80cf88c4-8a34-11dd-813c-806d6172696f} \Harddisk4\DP(1)0-0+b
i: 5,1 REM \Volume{80cf88c5-8a34-11dd-813c-806d6172696f} \Harddisk5\DP(1)0-0+c
j: 6,1 REM \Volume{80cf88c6-8a34-11dd-813c-806d6172696f} \Harddisk6\DP(1)0-0+d
e: x,x CDR \Volume{80cf88c2-8a34-11dd-813c-806d6172696f} \CdRom0

:unsure:

jaclaz

0

Share this post


Link to post
Share on other sites

Hi, Jaclaz.

Thanks for your feed back first.

The strange letter ¡ú is "→" I don't know if you can recognize it in IE.

Do send me your registry value of "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices". I must make a through check.

I have to point out that the drive letter order of a fixed hard disk is obtained by their volume offsets size ascendingly.

":sort" is the compare procedure, btw, IF command can compare hex values.

0

Share this post


Link to post
Share on other sites

Jaclaz

Though long time past since I have written above post, I think the problem you pointed out over and over. Finally, I think the problem comes from your ITALIAN xp system that is because of different system code.

I found a strang letter from your feedback too--"Jí". I don't know what it is.

I hope for a long time and again you could give your registry value of "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" for me to check.

My batch files have been downloaded by many Chinese and no bugs emerge since my last revision (same as here attached).

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.