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] batch file for ordering drive letter shifting


  • Please log in to reply
10 replies to this topic

#1
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
No matter which partition you installed your xp to by usb_multiboot_10, just run it, the drive letters will be ordered correctly. just add the batch code in undoren.cmd you don't affraid the drive letter shifting when installing xp using usb hard disk. Certainly, it is no need to change migrate.inf when installing xp using usb stick, thus we need change usb_multiboo_10.cmd, do it yourself.
===
batch content:

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

::get fixed drives
echo list disk >listdisk.txt
diskpart /s listdisk.txt >listresult.txt
for /f "skip=8 tokens=2 delims= " %%a in (listresult.txt) do (
echo select disk %%a >selectdisk%%a.txt
echo detail disk >>selectdisk%%a.txt
diskpart /s selectdisk%%a.txt >detaildisk%%a.txt
for /f "tokens=3 skip=17" %%b in (detaildisk%%a.txt) do (
echo %%b: >>fix.txt
)
del selectdisk%%a.txt
del detaildisk%%a.txt
)
del listdisk.txt
del listresult.txt

::get CDROM and removeable drives
FOR /F "tokens=*" %%a in ('fsutil fsinfo drives ^| FIND /V ""') DO (
set dr=%%a
SET dr=!dr:~-3,3!
SET cdr=!dr:~0,1!
IF !cdr! GTR B (
FOR /F "tokens=1 delims= " %%P IN ('fsutil fsinfo drivetype !dr! ^| FIND "CD-ROM"') DO (
SET vname=%%P
SET vname=!vname:~0,2!
echo !vname! >>CDROM.txt
)
FOR /F "tokens=1 delims= " %%P IN ('fsutil fsinfo drivetype !dr! ^| FIND /i "removable"') DO (
SET vname=%%P
SET vname=!vname:~0,2!
echo !vname! >>remove.txt
)
)
)

:: ording vid
for %%a in (fix.txt CDROM.txt remove.txt) do (
if exist %%a (
for /f %%b in (%%a) do (
IF %%b neq %systemdrive% (
mountvol %%b /l >drive.txt
mountvol %%b /d
for /f %%c in (drive.txt) do (
set vid=%%c
echo !vid! >>vid.txt
)
)
)
)
)

for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if %%d: neq %systemdrive% (
echo %%d >>drv.txt
)
)

if exist "fix.txt" del fix.txt
if exist "cdrom.txt" del cdrom.txt
if exist "remove.txt" del remove.txt

for /f "tokens=*" %%a in (vid.txt) do (
set /a n+=1
set _!n!=%%a
)

set n=0
for /f "tokens=*" %%i in (drv.txt) do call :lp %%i

for /f "tokens=1,2 delims= " %%a in ('findstr "\\" c.txt') do mountvol %%b: %%a
del drv.txt
del vid.txt
del drive.txt
del c.txt
exit
:lp
set /a n+=1
echo !_%n%!%1>>c.txt


===
below is original
After installing XP from USB hard disk, the drive D letter is for USB hard disk's first partition, while E F G ... is the first hard disk's second, third, fourth ... drive letter respectively. We need such drive order: C D E F drive letter belongs to the first hard disk, and G belongs to the USB hard disk.

These two files just do the job.
No prolem, its safe.

the content of drivechange.cmd

ECHO Program - DRVCHANG.CMD - 26 Sep 2008 - Date = %DATE% %TIME:~0,8%
CLS

rem SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

SET USBDRIVE=
SET TAGFILE=\usbflash

FOR %%h IN (C D E F G H I J K L M N O P Q R S T U V W X Y) DO IF EXIST "%%h:%TAGFILE%" SET USBDRIVE=%%h:
echo select disk 0 >selectdisk.txt
echo detail disk >>selectdisk.txt
diskpart /s selectdisk.txt >detaildisk.txt

echo %usbdrive:~0,1% >drv.txt

for /f "tokens=3 skip=18" %%a in (detaildisk.txt) do (
set drv=%%a
echo !drv! >>drv.txt
mountvol %%a: /l >drive.txt
for /f %%b in (drive.txt) do (
set vid=%%b
echo !vid! >>vid.txt
)
)

mountvol %usbdrive% /l >drive.txt
for /f %%c in (drive.txt) do set vid=%%c
echo %vid% >>vid.txt

call c.cmd

del selectdisk.txt
del detaildisk.txt
del drive.txt
del drv.txt
del vid.txt

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

EXIT


the content of c.cmd

@off
setlocal enabledelayedexpansion
if exist c.txt del /q c.txt
for /f "tokens=*" %%a in (vid.txt) do (
set /a n+=1
set _!n!=%%a
)
set n=0
for /f "tokens=*" %%i in (drv.txt) do call :lp %%i
goto :eof
:lp
set /a n+=1
echo !_%n%!%1>>c.txt


so, we can revise undoren.cmd and add above code and c.cmd file, drive leter will rearranged corrcetly after first logon.

I hope you can optimize two files in one.

Attached Files


Edited by victor888, 05 October 2008 - 02:37 AM.



How to remove advertisement from MSFN

#2
wimb

wimb

    Senior Member

  • Developer
  • 677 posts
The idea to use mountvol for rearranging the Drive Letters is interesting.
I have not yet used your batch files, but it seems to me that using disk 0 can be incorrect
in case your computer has e.g. two internal harddisks and you are installing on harrdisk 1 ;)

echo select disk 0 >selectdisk.txt


But in any way it will be interesting to implement and further improve the idea. ;)

#3
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
yes, I have considered this question. My main purpose the batch files are used for usb_multiboot10,so,most time xp is installed on the first hard disk.

As for on the second HD or more, the HD should be selected according to %home drive%.

#4
wimb

wimb

    Senior Member

  • Developer
  • 677 posts
you must first determine the harddisk nr of your %homedrive% using diskpart.

But that is not sufficient, in fact all local harddisks are involved in rearranging drive letters.

Edited by wimb, 27 September 2008 - 08:32 AM.


#5
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
There are should be no more difficulties.
We can give internal hard disks ordered drive letters and usb disk at last.

So, need more test and revising, wimb help.

#6
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
ok, try new batch again.

#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,056 posts
  • OS:none specified
  • Country: Country Flag
If I may :unsure:, it would be advisable to directly use the output of the commands, as to avoid the unneeded creation of some temporary files.
As an example this:
diskpart /s listdisk.txt >listresult.txt
for /f "skip=8 tokens=2 delims= " %%a in (listresult.txt) do (

can be "simplified" to:
for /f "skip=8 tokens=2 delims= " %%a in ('diskpart /s listdisk.txt') do (

And diskpart can be "fed" with commands, this:
echo list disk >listdisk.txt
diskpart /s listdisk.txt
can be obtained by:
echo list disk|diskpart.exe

Thus, overall, the whole:
echo list disk >listdisk.txt
diskpart /s listdisk.txt >listresult.txt
for /f "skip=8 tokens=2 delims= " %%a in (listresult.txt) do (
can become:
for /f "skip=8 tokens=2 delims= " %%a in ('echo list disk^|diskpart.exe') do (
with two temporary files less.

:)

jaclaz

#8
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
Many thanks to Jaclaz, hope you could optimiz it more.

Next I will revise it and make it fit for PE and normal installed xp.

Yet there is really a trouble thing, it is difficult to get the drive letters of two or more usb disks. If just one exist I can use tag file on it and use diskpart to get its drive letters.

This time I have to consider the influnce of virtual disk such as created by virtutal cd soft, subst and net use commands.

#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,056 posts
  • OS:none specified
  • Country: Country Flag

This time I have to consider the influnce of virtual disk such as created by virtutal cd soft, subst and net use commands.


You are welcome to use/copy/modify, if useful, my small batches here:
http://www.911cd.net...o...=21965&st=6

I am attaching a copy here also, should you have troubles in getting them from 911CD. :)

jaclaz

Attached Files



#10
Rich_Weiss

Rich_Weiss

    Newbie

  • Member
  • 20 posts
Is there a way to tweak this so it will map the disk type groupings to a certain range of drive letters rather than one drive letter after the other?
I would like to have the first CD/DVD drive map to drive R: and the next to S: etc. and the removable drives to end at drive Z:.

For Example

C: Local System Drive
D: Local Data Drive

N: Network Drive

R: CD ROM
S: DVD ROM

X: Removable Drive
Y: Removable Drive
Z: Removable Drive

#11
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
If the total drive letter doesn't exceed the R, S... that can be abtained.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN