Jump to content

more compatible batch file for ording drive letters


victor888

Recommended Posts

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
Link to comment
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
Link to comment
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

Link to comment
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?

Link to comment
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
Link to comment
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)

Link to comment
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

Link to comment
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
Link to comment
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.
×
×
  • Create New...