victor888

more compatible batch file for ording drive letters

42 posts in this topic

Thanks to Jaclaz for his help.

Temp files removed, running speed improved.

The problem of when booting pe from usb hard disk sometimes usb hard disk get number DISK 0 and internal hd get disk 1 was solved.

This batch file's former content view this: http://www.msfn.org/board/index.php?showtopic=123929

It is used under NT system such as win2k, PE, winxp and win2003. I haven't tested it under vista.

Do run it on system drive of virtual drive. Do remember to close all programs and files/folders stored on non-system-drive because during the running period it will unmount drives except system drive and virtual drives. It is ideal to run it on newly installed system i.e. installing xp from pe, direct installing xp by using usb stick or usb hard disk. For using usb_multiboot_10.cmd I think there is no need to revise migrate.inf to fix usb stick drive letter. Just run this batch as your need.

For non-Englisgh system, just change "removable" in this line:

::created by VICTOR888
::ordering drive letters by drive type
::ordered drive letters are assigned to fixed disk, cdrom, usb hard disk and usb stick
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

::get usbdisk amount
set /a usbdiskam=0
for /f %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum /s ^| find "USBSTOR"') do (
set /a usbdiskam=!usbdiskam!+1
)

::get removable usb disk amount and their drive letters
set /a remusbam=0

if %usbdiskam% GTR 0 (
FOR /F "tokens=*" %%a in ('fsutil fsinfo drives ^| FIND /V ""') DO (
set dr=%%a
SET dr=!dr:~-5,1!
IF !dr! GTR B (
FOR /F "tokens=1 delims= " %%P IN ('fsutil fsinfo drivetype !dr!: ^| FIND "re"') DO (
set /a remusbam=!remusbam!+1
SET vname=%%P
SET vname=!vname:~0,1!
call set remusb=%%remusb%% %%vname%%
)
)
)
)

::get fixed usb disk amount
if %usbdiskam% GTR 0 (
set /a fixedusbam=%usbdiskam%-%remusbam%
) else (
set /a fixedusbam=0
)

::get total hard disks amount
set /a totalhdam=0
for /f "skip=9 tokens=2" %%a in ('echo list disk ^| diskpart.exe') do (
set /a totalhdam=!totalhdam!+1
)

::get innternal fixed hard disk amount
set /a fixedhdam=%totalhdam%-%fixedusbam%

::get internal hard disk drive letters and fixed usb drive letters
if %fixedusbam% equ 0 (
for /f "skip=9 tokens=2" %%a in ('echo list disk ^| diskpart.exe') do (
echo select disk %%a >selectdisk%%a.txt
echo detail disk >>selectdisk%%a.txt
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk%%a.txt') do (
set dr=%%b
call set fixdrv=%%fixdrv%% %%dr%%
)
del selectdisk%%a.txt
)
) else (
for /f "tokens=1 delims=\" %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum /v 0 ^| find "REG_SZ"') do set hd=%%a
if "%hd:~-7%" neq "USBSTOR" (
for /f "skip=9 tokens=2" %%a in ('echo list disk ^| diskpart.exe') do (
set /a counter=!counter!+1
echo select disk %%a >selectdisk%%a.txt
echo detail disk >>selectdisk%%a.txt
if !counter! LEQ %fixedhdam% (
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk%%a.txt') do (
set dr=%%b
call set fixdrv=%%fixdrv%% %%dr%%
del selectdisk%%a.txt
)
) else (
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk%%a.txt') do (
set dr=%%b
call set hdusb=%%hdusb%% %%dr%%
del selectdisk%%a.txt
)
)
)
) else (
echo select disk 0 >selectdisk0.txt
echo detail disk >>selectdisk0.txt
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk0.txt') do (
set dr=%%b
call set hdusb=%%hdusb%% %%dr%%
del selectdisk0.txt
)
for /f "skip=10 tokens=2" %%a in ('echo list disk ^| diskpart.exe') do (
set /a counter=!counter!+1
echo select disk %%a >selectdisk%%a.txt
echo detail disk >>selectdisk%%a.txt
if !counter! LEQ %fixedhdam% (
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk%%a.txt') do (
set dr=%%b
call set fixdrv=%%fixdrv%% %%dr%%
del selectdisk%%a.txt
)
) else (
for /f "tokens=3 skip=17" %%b in ('diskpart /s selectdisk%%a.txt') do (
set dr=%%b
call set hdusb=%%hdusb%% %%dr%%
del selectdisk%%a.txt
)
)
)
)
)

::get all drive letters except A
FOR /F "tokens=*" %%b in ('fsutil fsinfo drives ^| FIND /V ""') DO (
set dr=%%b
SET dr=!dr:~-5,1!
IF !dr! GTR B call set alldrv=%%alldrv%% %%dr%%
)

::get drive letters with mount point
FOR /F %%a in ('mountvol ^| findstr :\') do (
set dr=%%a
set dr=!dr:~0,1!
IF !dr! GTR A call set mountdrv=%%mountdrv%% %%dr:~0,1%%
)
)

::get virtual drives created by virtual CD soft, command subst, net use and ram disk etc.
set virdrv=%alldrv%
for %%a in (%mountdrv%) do call set virdrv=%%virdrv:%%a=%%
set virdrv=%virdrv% %systemdrive:~0,1%

::get CDROM drive letters
FOR /F "tokens=*" %%a in ('fsutil fsinfo drives ^| FIND /V ""') DO (
set dr=%%a
SET dr=!dr:~-5,1!
IF !dr! GTR A (
FOR /F "tokens=1 delims= " %%P IN ('fsutil fsinfo drivetype !dr!: ^| FIND "CD-ROM"') DO (
SET vname=%%P
SET vname=!vname:~0,1!
for /f %%b in ('mountvol !vname!: /l ^| find "\\"') do call set cdrom=%%cdrom%% %%vname%%
)
)
)

::ordering drive letters by internal fixed hard disk, cdrom, hard usb disk and removalbe usbdisk

set neworder=%fixdrv% %cdrom% %hdusb% %remusb%

set fulldrv=CDEFGHIJKLMNOPQRSTUVWXYZ
for %%a in (%virdrv%) do call set fulldrv=%%fulldrv:%%a=%%

:: get ordered vid
set /a n=0
for %%a in (%neworder%) do (
if %%a neq %systemdrive:~0,1% (
for /f %%b in ('mountvol %%a: /l') do (
mountvol %%a: /d
call echo %%b %%fulldrv:~!n!,1%%: >>c.txt
set /a n+=1
)
)
)

for /f "tokens=1,2 delims= " %%a in (c.txt) do mountvol %%b %%a
del c.txt

orderdrv3.rar

Edited by victor888
0

Share this post


Link to post
Share on other sites
Thanks to Jaclaz for his help.

You are welcome. :)

I changed the board tags from CODE to CODEBOX as to make the thread more readable.

At first sight you still have a number of temporary text files:

remusb.txt

selectdisk%%a.txt

fixdrv.txt

hdusb.txt

alldrv.txt

mountdrv.txt

tempfile.txt

tempfile2.txt

virdrv.txt

CDROM.txt

remusb.txt

vid.txt

drv.txt

c.txt

I'll see, as soon as I have some spare time, if I can find some ways to remove (or minimize) the need for temp files.

jaclaz

P.S.: Maybe this approach may work?

Just an example, first "separate" Removable drives from Fixed .....:


@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN ( A B C D E F G H I J K L M N O P Q R S T U V Z) DO (
FOR /F "tokens=1,2,3,4 delims= " %%B IN ('REG QUERY HKLM\SYSTEM\MountedDevices\ /V \DosDevices\%%A: 2^>^&1^|FIND "REG_BINARY"') DO (
REM ECHO %%A %%B %%C %%D

CALL :Drivetype %%A %%D
)
)
SET First8
SET FIXED
SET REMOVABLE
PAUSE
GOTO :EOF

:Drivetype
SET DRIVE_%1=%2
CALL SET First8_%1=!DRIVE_%1:~0,8!
IF !First8_%1!.==5C003F00. (SET REMOVABLE=%REMOVABLE%%1:,) ELSE (SET FIXED=%FIXED%%1:,)
GOTO :EOF

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

I think registry site mounteddevice is not reliable because when a removable device unpluged the drive letter and mount point still exist.

0

Share this post


Link to post
Share on other sites
I think registry site mounteddevice is not reliable because when a removable device unpluged the drive letter and mount point still exist.

Yes, you are right, but it may help in "limiting" the range, like a pre-check.

Take it as a "heuristic" approach, ;), drive letters that won't be found in the Registry were never been assigned. :)

jaclaz

0

Share this post


Link to post
Share on other sites

I downloaded a slimmed down version of XP (XP Performance Edition). When I browse to this folder, I get the error that WINNT32.EXE is not found and that certain options should not be used when slimming XP down with nLite.

I do not know if the person who made this slimmed down version did just that, but is it somehow possible to get things working? I have a bootable iso image and a usb stick. Somehow this should be able to work, right?

0

Share this post


Link to post
Share on other sites

as long has the command fsutil, mountvol, diskpart and findstr exist, the batch does work.

0

Share this post


Link to post
Share on other sites
I downloaded a slimmed down version of XP (XP Performance Edition). When I browse to this folder, I get the error that WINNT32.EXE is not found and that certain options should not be used when slimming XP down with nLite.

Sure, and you expect to get help and support for a WAREZ release? :unsure:

Check Rules:

http://www.msfn.org/board/Forum-Rules-Updated-Re-t18408.html

I do not know if the person who made this slimmed down version did just that, but is it somehow possible to get things working? I have a bootable iso image and a usb stick. Somehow this should be able to work, right?

I guess both you and the "the person who made this slimmed version" have failed to read the FAQ's, that version has probably "Operating System Options-->Manual Install and Upgrade for removal" REMOVED.

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites
Sure, and you expect to get help and support for a WAREZ release?

I have a original XP cd-rom (which I don't use more on my Vista desktop). I don't understand why this would be illegal (you can alter a product you have legally bought). I thought that is why programs like nLite are out there. (BTW "the other person" is actually another person)

0

Share this post


Link to post
Share on other sites
I have a original XP cd-rom (which I don't use more on my Vista desktop). I don't understand why this would be illegal (you can alter a product you have legally bought). I thought that is why programs like nLite are out there. (BTW "the other person" is actually another person)

If you build out of your original XP CD, unless you used nlite too aggressively, removing thing you should have not, it will work.

You mentioned downloading "XP Performance Edition", which is a known WAREZ release.

jaclaz

0

Share this post


Link to post
Share on other sites

Not yet had enough time to go through it, however, it seems to me that you forget the possibility of a SCSI drive and of a Removable SCSI drive.

Get the the Perisoft minifile and miniram drivers and try it:

http://www.perisoft.net/miniport/index.htm

jaclaz

0

Share this post


Link to post
Share on other sites

SCSI drive is concerned too.

Edited by victor888
0

Share this post


Link to post
Share on other sites

I had a somewhat deeper look at the batch.

It is a GOOD idea and the code is OK :thumbupBUT, in a nutshell, I do not like it. :blink:

I mean, I feel like it is overly complex, and it is possible that it won't work on some localized versions. (changing the "Removable" to "mov" should cover a number of European ones)

I did a couple of check and some temp files can be made unneeded.

Still, I could not find a way to manage diskpart without a temp file.

While researching about it, I found something I had never seen (or better never paid attention to) that may be a better approach:

WMIC (Windows Management Instrumentation Command):

http://www.ss64.com/nt/wmic.html

http://www.robvanderwoude.com/wmic.html

http://www.robvanderwoude.com/wmigen.html

http://www.robvanderwoude.com/arrays_bat.html

Maybe this could be a "slimmer" approach. :unsure:

Check the attached example.

jaclaz

testwmic.zip

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

I need your optimized version.

I think of using wmic but do not study it.

Your sample is really very good.

WMIC command is too powerful.

Edited by victor888
0

Share this post


Link to post
Share on other sites

Jaclaz go!

I am studying wmi/wmic these days too, hope an smart script come out ealier under your work and my support.

0

Share this post


Link to post
Share on other sites

Find attached another example.

Nothing actually working, but a little step further. :unsure:

Check testwmic3.cmd:

Finding the escaping characters needed to use the "Where" operator with the value "Disk #m, Partition #n" and redirecting failing instances to nul can only be described as a nightmare! :w00t:

Rule seems to be that you need to enclose the Where argument into brackets () to be able to use the quotes "" inside it, and when in a FOR loop:

equal sign = needs to be escaped

quotes " and commas , (that normally would need to be escaped) need NOT to be escaped

jaclaz

testwmic2_3.zip

0

Share this post


Link to post
Share on other sites

It seems to me that after all WMIC is not "the" solution, but it may be part of it.

I seem not to be able through WMIC to "find a relationship" between PHYSICALDRIVEs and LogicalDrives when the device is "Removable".

Moreover it seems like the available data go as deep as finding Extended Partitions but not deep enough to find Logical Volumes inside them.

Find attached another example, it seems to me that it gathers all available data through WMIC. :unsure:

jaclaz

getdriveletters.zip

0

Share this post


Link to post
Share on other sites

Almost, but not quite, completely unrelated ;)

symbol2mvol.cmd

Uses:

Listdosdevices:

http://www.uwe-sieber.de/drivetools_e.html

VLM (part of the DSFOK package):

http://members.ozemail.com.au/~nulifetv/freezip/freeware/

Output sample:

C:\Downloaded\victor888>symbol2mvol
C: FIX \\.\Volume{b0b284c3-8a33-11dd-8781-806d6172696f} \HarddiskVolume1
D: CDR \\.\Volume{80cf88c2-8a34-11dd-813c-806d6172696f} \CdRom0
E: FIX \\.\Volume{b0b284c4-8a33-11dd-8781-806d6172696f} \HarddiskVolume2
G: REM \\.\Volume{80cf88c4-8a34-11dd-813c-806d6172696f} \Harddisk4\DP(1)0-0+b
H: REM \\.\Volume{80cf88c5-8a34-11dd-813c-806d6172696f} \Harddisk5\DP(1)0-0+c
I: REM \\.\Volume{80cf88c6-8a34-11dd-813c-806d6172696f} \Harddisk6\DP(1)0-0+d
J: FIX \\.\Volume{98f06d4c-9506-11dd-8147-001fc6bb76ce} \HarddiskVolume3
K: FIX \\.\Volume{98f06d4d-9506-11dd-8147-001fc6bb76ce} \HarddiskVolume4
L: FIX \\.\Volume{98f06d4e-9506-11dd-8147-001fc6bb76ce} \HarddiskVolume5
M: FIX \\.\Volume{98f06d4f-9506-11dd-8147-001fc6bb76ce} \HarddiskVolume6
N: REM \\.\Volume{80cf88c3-8a34-11dd-813c-806d6172696f} \Harddisk3\DP(1)0-0+a
S: REM \\.\Volume{5d3e8800-9c1f-11dd-8148-001fc6bb76ce} \Harddisk2\DP(1)0-0+5

Runnning listdosdevices with a /? parameters outputs a mess of data, maybe it can be useful. :unsure:

A similar app is dosdev:

http://www.ltr-data.se/opencode.html

and on the same page there is devioctl.

Devioctl with the GEOMETRY <drive> parameters gives the needed info, <drive> can be:

  • drive letter
  • PhysicalDriven

(but it won't work -obviously- :unsure: for Removable devices where no media is inserted :()

jaclaz

symbol2mvol.cmd

Edited by jaclaz
0

Share this post


Link to post
Share on other sites
DiskExt v1.1 which gives each disk it mount volume and drive letters.

Yep :), but it won't give you ANY more info than mountvol for Removable devices like SD card readers when there is no media in them.....:(

A more useful app is the dd for windows version by John Newbigin:

http://www.chrysocome.net/dd

try running

dd --list

;)

jaclaz

Edited by jaclaz
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.