MSFN Forum: more compatible batch file for ording drive letters - MSFN Forum

Jump to content


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

more compatible batch file for ording drive letters updated on 1 Nov. 2008

#1 User is offline   victor888 

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

Posted 11 October 2008 - 06:32 PM

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
 

Attached File(s)


This post has been edited by victor888: 01 November 2008 - 08:07 AM



#2 User is offline   jaclaz 

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

Posted 13 October 2008 - 07:39 AM

View Postvictor888, on Oct 12 2008, 02:32 AM, said:

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:

Quote

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
 

This post has been edited by jaclaz: 13 October 2008 - 07:58 AM


#3 User is offline   victor888 

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

Posted 13 October 2008 - 04:36 PM

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

#4 User is offline   jaclaz 

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

Posted 14 October 2008 - 01:41 AM

View Postvictor888, on Oct 14 2008, 12:36 AM, said:

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

#5 User is offline   victor888 

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

Posted 14 October 2008 - 08:37 AM

That is true.

hope your optimized version.

#6 User is offline   bobob 

  • Group: Members
  • Posts: 2
  • Joined: 01-March 07

Posted 15 October 2008 - 02:40 PM

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?

#7 User is offline   victor888 

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

Posted 15 October 2008 - 03:42 PM

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

#8 User is offline   jaclaz 

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

Posted 16 October 2008 - 02:03 AM

View Postbobob, on Oct 15 2008, 10:40 PM, said:

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/...-Re-t18408.html

View Postbobob, on Oct 15 2008, 10:40 PM, said:

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

This post has been edited by jaclaz: 16 October 2008 - 02:04 AM


#9 User is offline   bobob 

  • Group: Members
  • Posts: 2
  • Joined: 01-March 07

Posted 16 October 2008 - 11:36 AM

View Postjaclaz, on Oct 16 2008, 03:03 AM, said:

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)

#10 User is offline   jaclaz 

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

Posted 16 October 2008 - 12:58 PM

View Postbobob, on Oct 16 2008, 07:36 PM, said:

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

#11 User is offline   victor888 

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

Posted 19 October 2008 - 07:33 PM

Jaclaz, check it again.

#12 User is offline   jaclaz 

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

Posted 20 October 2008 - 01:33 PM

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....iport/index.htm

jaclaz

#13 User is offline   victor888 

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

Posted 20 October 2008 - 04:43 PM

SCSI drive is concerned too.

This post has been edited by victor888: 20 October 2008 - 09:34 PM


#14 User is offline   jaclaz 

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

Posted 22 October 2008 - 08:07 AM

I had a somewhat deeper look at the batch.

It is a GOOD idea and the code is OK :thumbup BUT, 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.robvander...e.com/wmic.html
http://www.robvander...com/wmigen.html
http://www.robvander...arrays_bat.html

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

Check the attached example.

jaclaz

Attached File(s)


This post has been edited by jaclaz: 22 October 2008 - 08:10 AM


#15 User is offline   victor888 

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

Posted 22 October 2008 - 08:18 AM

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.

This post has been edited by victor888: 22 October 2008 - 09:38 AM


#16 User is offline   victor888 

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

Posted 27 October 2008 - 07:45 AM

WMI is too powerful, most valuable link: http://www.windows-management.com/scriptin...cal/#ADPPDD.htm

FOR WIN2K3 AND VISTA diskpart, mountvol etc are of no use.

This post has been edited by victor888: 27 October 2008 - 08:32 PM


#17 User is offline   jaclaz 

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

Posted 28 October 2008 - 12:58 AM

View Postvictor888, on Oct 27 2008, 02:45 PM, said:

WMI is too powerful, most valuable link: http://www.windows-management.com/scriptin...cal/#ADPPDD.htm


Nice VBS script. :)

I'll try to replicate it's approach.

jaclaz

#18 User is offline   victor888 

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

Posted 28 October 2008 - 01:45 AM

Jaclaz go!

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

#19 User is offline   jaclaz 

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

Posted 29 October 2008 - 05:44 AM

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

Attached File(s)



#20 User is offline   victor888 

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

Posted 29 October 2008 - 06:55 AM

Very good example. I will study it asap.

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