MSFN Forum: [updated] batch file for ordering drive letter shifting - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[updated] batch file for ordering drive letter shifting change drive letter to normal orded value

#1 User is offline   victor888 

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

  Posted 26 September 2008 - 09:33 PM

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:

Quote

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

Quote

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

Quote

@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 File(s)


This post has been edited by victor888: 05 October 2008 - 02:37 AM



#2 User is offline   wimb 

  • Senior Member
  • Group: Developers
  • Posts: 633
  • Joined: 21-March 07

Posted 27 September 2008 - 01:23 AM

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

Quote

echo select disk 0 >selectdisk.txt


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

#3 User is offline   victor888 

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

Posted 27 September 2008 - 01:59 AM

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

  • Senior Member
  • Group: Developers
  • Posts: 633
  • Joined: 21-March 07

Posted 27 September 2008 - 04:07 AM

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.

This post has been edited by wimb: 27 September 2008 - 08:32 AM


#5 User is offline   victor888 

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

Posted 27 September 2008 - 08:22 AM

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

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

Posted 05 October 2008 - 02:38 AM

ok, try new batch again.

#7 User is offline   jaclaz 

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

Posted 05 October 2008 - 05:36 AM

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

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

Posted 05 October 2008 - 07:24 AM

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

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

Posted 05 October 2008 - 07:31 AM

View Postvictor888, on Oct 5 2008, 03:24 PM, said:

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/forums//index.php?sho...=21965&st=6

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

jaclaz

Attached File(s)



#10 User is offline   Rich_Weiss 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 12-September 08

Posted 03 June 2009 - 10:26 PM

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

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

Posted 07 June 2009 - 07:09 PM

If the total drive letter doesn't exceed the R, S... that can be abtained.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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



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