MSFN Forum: [Updated on Feb. 27. 2011] ordering messed drive letter batch file - MSFN Forum

Jump to content


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

[Updated on Feb. 27. 2011] ordering messed drive letter batch file Getting whole drive letter information from registry.

#21 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 09 December 2008 - 06:58 AM

Very good example though it is language related.
I use English mountvol.exe to test it.
The result is very very good.

This post has been edited by victor888: 09 December 2008 - 07:37 AM



#22 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 09 December 2008 - 09:54 AM

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

This post has been edited by jaclaz: 10 December 2008 - 02:51 AM


#23 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 09 December 2008 - 06:10 PM

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 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 11 December 2008 - 11:05 PM

A good command to turn localized system in to English: chcp 437

#25 User is offline   an3k 

  • Junior
  • Pip
  • Group: Members
  • Posts: 95
  • Joined: 15-June 08
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 12 December 2008 - 10:46 AM

View Postjaclaz, on Dec 9 2008, 04:54 PM, said:

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

#26 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 12 December 2008 - 12:19 PM

View Postan3k, on Dec 12 2008, 05:46 PM, said:

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
 


#27 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 07 June 2009 - 07:00 PM

updated again.

#28 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 10 July 2009 - 09:20 AM

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:

Quote

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

#29 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 15 July 2009 - 08:04 PM

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.

#30 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 01 August 2009 - 05:53 AM

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).

#31 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 01 August 2009 - 06:57 AM

View Postvictor888, on Aug 1 2009, 01:53 PM, said:

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).


Sorry Victor, I completely forgot.

Find attached:
the output of ddlistw on my system "as is now" (which is different from last report)
the exported MountedDevices
the output of the MBRFIX version
the output of the DISKPART version


Apart from the problem reported, you SHOULD NOT allow the batch to actually attempt reordering drive letters WITHOUT and explicit confirmation by the user.
Using the batch as is may botch the setup of an unexperienced user.
It happened to my system, though of course I know how to fix it.

In this:

Quote

::two founds with using batch file
::1. "?"¡¡can not be as an element of string in the for command
::2. one variable can not contain another varable in for command i.e. for %%a in (!ab%c%!) do ..., !ab%c%! has no value

the ¡¡ are A1A1 hex

Quote

: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


the ¡ú are A1FA hex

jaclaz

Attached File(s)



#32 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 01 August 2009 - 10:20 PM

Hi, Jaclaz

I am sure there something strange in your registry:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum, where a unrecognizable disk exist.

So do include here your this registry values.

#33 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 02 August 2009 - 04:37 AM

View Postvictor888, on Nov 14 2008, 04:23 AM, said:

This batch work under winpe and winnt systems(2k,2k3,xp,vista)

Your code appears to completely ignore Windows 2000.
You only supply mountvol executables for 2k3, xp and vista, but I'm sure that 2k doesn't work with later versions of mountvol and there's no check for Reg.exe which is not by default part of the Windows 2000 OS!

#34 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 03 August 2009 - 01:15 AM

I have no win2k system to check, if you can, let me know result.

#35 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 03 August 2009 - 02:32 AM

View Postvictor888, on Aug 2 2009, 06:20 AM, said:

Hi, Jaclaz

I am sure there something strange in your registry:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum, where a unrecognizable disk exist.

So do include here your this registry values.


Rest assured that there is NOTHING "strange" in my Registry :w00t:, and particularly NOT in HKLM\\SYSTEM\CurrentControlSet\Services\Disk\Enum. ;)

However, find attached the relevant exported key. :)

jaclaz

Attached File(s)



#36 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 03 August 2009 - 03:45 AM

View Postvictor888, on Aug 3 2009, 08:15 AM, said:

I have no win2k system to check, if you can, let me know result.
There will be no result, without a version of reg.exe which uses the syntax used in your script; or access to the correct version of mountvol.exe your script will not work on Windows 2000!

#37 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 03 August 2009 - 09:32 AM

Hi, above.

You are right, it is my fault, the batches don't fit for WIN2K system.

#38 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 03 August 2009 - 09:36 AM

Hi, Jaclaz

My suspiiion is right, your HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum has a strange value---"2"="SCSI\\Disk&Ven_Perisoft&Prod_Virtual_Disk&Rev_0001\\1&2afd7d61&1&000", a virtual disk which has no sigcode and can't be displayed by diskpart.

To meet this special situation, I have to revise my code again. Please wait for a short time.

Thank you for testing it!

#39 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,458
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 03 August 2009 - 05:11 PM

View Postvictor888, on Aug 3 2009, 05:36 PM, said:

My suspiiion is right, your HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum has a strange value---"2"="SCSI\\Disk&Ven_Perisoft&Prod_Virtual_Disk&Rev_0001\\1&2afd7d61&1&000", a virtual disk which has no sigcode and can't be displayed by diskpart.


It's not "strange":
http://dictionary.re.../browse/strange
, in the sense of

Quote

4. outside of one's previous experience; hitherto unknown; unfamiliar: strange faces; strange customs.


Looky here :whistle::
http://www.msfn.org/board/index.php?showto...24539&st=11
;)

I actually "introduced" it at the time in order to have a "particular" situation.....

:lol:

jaclaz

#40 User is offline   victor888 

  • Member
  • PipPip
  • Group: Members
  • Posts: 155
  • Joined: 20-October 04

Posted 03 August 2009 - 06:05 PM

Jaclaz is an odd guy.
My English is poor.
Tonight I will give revised version.

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy