Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

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


  • Please log in to reply
57 replies to this topic

#1
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
1. Can fix flash disk driver letter:

Seletion to fix flash disk driver letter:
set USBDRV=U

"U" is your flash drive letter to be fixed, you may change it as your need.
For FIXED USB DISK (usb hard disk or fixed type usb disk) this selection nas no meaning.
Also it is not fit to the condition that more than 1 flash disk exists.
Do be sure that flash USB drive letter is not confilict with any other existing drive letter.

1. support WIN7 (WIN7 PE).
2. support VHD disk recognition.
3. code optimized.
4. add Automated run selection.

selection for automated run
 set AUTO=n (default is n, which means no intercourse needed. if AUTO was set to y, means automatic mode is opened.)
===
Special thanks to Jaclaz.
===
Function: order messed drive letters caused by, for example, installing xp from usb (removabe or hard disk), startting pe from usb etc.

Win command used: reg (to query information from registry), find (combine with other command), wimc (to get all drive letters. For PE, all drive letters are find from registry ), mountvol (to change drive letters), diskpart.exe (to get disk drive letters, only for diskpart version)

Workround: This batch work under winpe and winnt systems(XP,2k3,vista and WIN7).

Note:
1. Don not run subst or net use prior to running it.

Attached Files


Edited by victor888, 27 February 2011 - 12:55 AM.



How to remove advertisement from MSFN

#2
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
If you have any difficulties in understanding this batch, just let me know. I will give details.

Edited by victor888, 20 November 2008 - 07:12 AM.


#3
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
Jaclaz try this again.

#4
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

Jaclaz try this again.


Will do, thanks. :)
...and let you know ....;)

jaclaz

P.S.: Quicly tested, it doesn't work (properly) for me, though I see it as a great improvement over the "old" one :)
C:\Downloaded\victor888>regorderdrv
all drive letters:  C D E G H I J K L M N R
mounted drive letters:  i C E D R N G H I J K L M
virtual drive letters:
internal hard disk 1 drive letter:  C

Errore:  impossibile trovare la chiave del Registro di sistema o il valore specificato

Errore:  impossibile trovare la chiave del Registro di sistema o il valore specificato
usb hard disk 1 drive letters: E
usb hard disk 2 drive letters: J K L M
floppy drive letters:
cd/dvd rom drive letters:  D
remmovalbe drive letters:  i R N G H I
Legend:

Errore: impossibile trovare la chiave del Registro di sistema o il valore specificato

=

Error cannot find specified Registry key or value


Real situation:
1) internal (SATA) drives: C:, E: :(
2) CD D: :)
3) USB hard disk J: K: L: M: :)
4) Removable (SD card reader, 4 slots) G: H: I: N:
5) Virtual disk (removable - Perioft demo driver) R:

Edited by jaclaz, 20 November 2008 - 09:47 AM.


#5
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
Ok, mounted drive letter "i" is incorrect.

Please show me the result of MOUNTVOL.EXE.

For drive letter R:, it must have has a volume id and been recognized as removable device.

Edited by victor888, 20 November 2008 - 07:32 PM.


#6
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
OK, I will get mount point from registry, not from MOUNTVOL.EXE and make optimization.

#7
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
JACLAZ try again.

#8
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
revised again.

#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
VERY GOOD WORK! :)

Still something that must be taken into account (I know I am picky, but that should be the right attitude for "testers") ;):
regorderdrv
All drive letters:  C D E F G H I N R X
Mounted drive letters:  C E D R N G H I
Virtual drive letters:  FX
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}I {80c
f88c6-8a34-11dd-813c-806d6172696f}I {80cf88c6-8a34-11dd-813c-806d6172696f}I {80c
f88c6-8a34-11dd-813c-806d6172696f}I
Cd/dvd rom drive letters:  D
Remmovalbe drive letters:  R N G H I

subst
X:\: => C:\WINPE BUILDER\X
I added a SUBST drive, just to see how it would behave. :whistle:
C: and E: are Internal Fixed Disks
D: is CD-ROM
F: is a IMDISK Virtual Disk
X: is the SUBSTed drive
R: is the Perisoft Virtual Disk
N: G: H: I: are partitions on external USB

A small typo:

Remmovalbe Removable drive letters: R N G H I


The listed virtual drive letters miss a separator.

I would use the "normal" convention of colons and the comma as separator, like:

All drive letters: C:, D:, E:, F:, G:, H:, I:, N:, R:, X:


I will try a combo of more Virtual Disks and post results....;)

jaclaz

P.S.:
@ALL
If you want to test this batch, add a GOTO :EOF here:

GOTO :EOF

::remove system drive letters and volume ids

so that drive letters are NOT re-ordered

Edited by jaclaz, 24 November 2008 - 05:07 AM.


#10
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
Perhaps I am lost in registry searching.

This CMD will take usb hard disk as internal hard disk if booted with pe on usb hard disk and drive letter c belongs to it.
Sometimes when boot pe, no "diskperipheral " value found in registy which reselts to no internal hard disk found.

Edited by victor888, 24 November 2008 - 08:02 PM.


#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
No joy yet (version dated 30/11/2008). :(
regorderdrv
All drive letters:  C D E F G H I J K L M N O
Mounted drive letters:  C D I J K L M N E G H O F
Internal hard disk 1 drive letter:  C
Usb hard disk 1 drive letters: D
Usb hard disk 2 drive letters: E G H O
Cd/dvd rom drive letters:  I
Remmovalbe drive letters:  J K L M N F
D: is second internal hard disk.
E: G: H: O: are first (and only) USB HD.

There is no distinction among the various Remmovalbe Removable drives:
F: is a USB stick
J: is Perisoft Virtual SCSI disk
K: L: M: N: are USB Card Reader Combo.

You "changed the rules" ;) of the game, however. :whistle:

The point was - at least in my mind - to use no external utility, otherwise most of the fun would be lost. :ph34r:


It will take me some time to check the batch code, will let you know If I find where the problem might be....

Cheers,

jaclaz

#12
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
Thank you very much, you poitns its bug, second hard disk wrong.

I disklike break the rule too.
I have to use dispart to replace mbrfix.

a revised version will coming soon.

Edited by victor888, 03 December 2008 - 04:46 PM.


#13
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
I like to play along the rules of the "game" ;)

Try the attached. :whistle:

A bit slowish, needs polishing and betterings, but maybe we're getting somewhere :unsure:. (only REG.EXE and MOUNTVOL.EXE is used, NO temporary files)

Cheers,
jaclaz

Attached Files



#14
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
Well done.

A:
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: 0,5 IDE	  Fixed
I: 0,6 IDE	  Fixed
J: 0,7 IDE	  Fixed
K: 0,8 IDE	  Fixed
L:	 IDE	  CD-ROM
M:	  Fixed
N: 1,0 USB	  Removabl
O: 3,0 USB	  Removabl
P: 4,0 USB	  Removabl
Q: 5,0 USB	  Removabl
R:	  Fixed

The result is correct.
One problem is it doesn't tell where are USB hard disk drive letters type (M: R:). Only give FIXED drive letter.

Addition: for winpe, sometimes no item under DISKPERIPHERAL, so no signature found.

Anoter thing, this batch doesn't arrange drive letters according to volume order.

I should further examine your code.

thanks.

Edited by victor888, 07 December 2008 - 04:14 AM.


#15
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
It works for my USB external hard disk:

C: 0,0 IDE	  Fixed
D: 1,0 IDE	  Fixed
E: 7,0 USB	  Fixed
G: 7,1 USB	  Fixed
H: 7,2 USB	  Fixed
I:	 IDE	  CD-ROM
J: 2,0 SCSI	 Removable
K: 3,0 USB	  Removable
L: 4,0 USB	  Removable
M: 5,0 USB	  Removable
N: 6,0 USB	  Removable
O: 7,3 USB	  Fixed

(letters E: G: H: O: ) :unsure:

Try using the /v switch and post output.....

About ordering, at the end of the batch "main", after:
FOR /F "Tokens=2 delims==" %%? IN ('SET LDrive') DO ECHO %%?
and before:
GOTO :EOF

These two lines:

ECHO.
FOR /F "Tokens=2 delims==" %%? IN ('SET LDrive ^|SORT /+14') DO ECHO %%?


Output becomes this ;):
C: 0,0 IDE	  Fixed
D: 1,0 IDE	  Fixed
E: 7,0 USB	  Fixed
G: 7,1 USB	  Fixed
H: 7,2 USB	  Fixed
I:	 IDE	  CD-ROM
J: 2,0 SCSI	 Removable
K: 3,0 USB	  Removable
L: 4,0 USB	  Removable
M: 5,0 USB	  Removable
N: 6,0 USB	  Removable
O: 7,3 USB	  Fixed

I:	 IDE	  CD-ROM
C: 0,0 IDE	  Fixed
D: 1,0 IDE	  Fixed
J: 2,0 SCSI	 Removable
K: 3,0 USB	  Removable
L: 4,0 USB	  Removable
M: 5,0 USB	  Removable
N: 6,0 USB	  Removable
E: 7,0 USB	  Fixed
G: 7,1 USB	  Fixed
H: 7,2 USB	  Fixed
O: 7,3 USB	  Fixed

We could give a "fake" physical drive number to CD-ROM(s) to alter the order.

PE is a different thing....:unsure:

Also I need to know how would a SATA CD/DVD behave....:unsure:

And however I am not so sure that entries in Services\Disk\Enum are the same as the output of WMIC.....this needs to be checked thoroughfully.
EDIT:
Checked, and unfortunately they do not correspond :( a similar batch using WMI gives different results:
C: 0_0 IDE	  Fixed [HD]	  MAXTOR STM3320820AS
D: 1_0 IDE	  Fixed [HD]	  MAXTOR STM3320820AS
E: 3_0 USB	  Fixed [HD]	  SAMSUNG HD320KJ USB Device
G: 3_1 USB	  Fixed [HD]	  SAMSUNG HD320KJ USB Device
H: 3_2 USB	  Fixed [HD]	  SAMSUNG HD320KJ USB Device
J: 2_0 SCSI	 Removable [HD]  Perisoft Virtual Disk SCSI Disk Device
K: 4_0 USB	  Removable	   Generic USB SD Reader USB Device
L: 5_0 USB	  Removable	   Generic USB CF Reader USB Device
M: 6_0 USB	  Removable	   Generic USB SM Reader USB Device
N: 7_0 USB	  Removable	   Generic USB MS Reader USB Device
O: 3_3 USB	  Fixed [HD]	  SAMSUNG HD320KJ USB Device

Additionally mountvol does not detect IMDISK Virtual Disks :(:
http://www.boot-land...?showtopic=3909

I guess we need to find out how to manage correctly the entries in \DosDevices and forget about mountvol.

The FREEDRV I wrote some time ago could be part of the solution...I will have to study it (I am getting old an cannot even say if it used mountvol or not....):
http://www.911cd.net...o...=21965&st=6

EDIT:
Checked, no way to detect IMDISK volumes through Mountvol or Registry....

jaclaz

P.S.: On the machine I tried it I don't have a floppy, thus it is not "detected" at all (there is NO code for it), but I think anyway that it would be advisable to simply "exclude" A: and B: from the mountvol command, you aren't going to change those drive letters, are you?

Edited by jaclaz, 07 December 2008 - 09:32 AM.


#16
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
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.

#17
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
@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

#18
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
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.....;extra=page=2

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.

#19
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
Boy, do I love Google translate!:
http://translate.goo...t...en&ie=UTF-8

This is great:

The Scarlet Letter is part of the sub-signature

Nathaniel Hawthorne would be very glad for this publicity to his book.... :thumbup

jaclaz

#20
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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, 10 December 2008 - 02:50 AM.


#21
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
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, 09 December 2008 - 07:37 AM.


#22
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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, 10 December 2008 - 02:51 AM.


#23
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
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.

#24
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
  • Joined 20-October 04
A good command to turn localized system in to English: chcp 437

#25
an3k

an3k

    Junior

  • Member
  • Pip
  • 95 posts
  • Joined 15-June 08
  • OS:Windows 7 x64
  • Country: Country Flag

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users