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

more compatible batch file for ording drive letters


  • Please log in to reply
41 replies to this topic

#1
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 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/...howtopic=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 stickSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSION::get usbdisk amountset /a usbdiskam=0for /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 lettersset /a remusbam=0if %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 amountif %usbdiskam% GTR 0 (  set /a fixedusbam=%usbdiskam%-%remusbam%) else (  set /a fixedusbam=0)::get total hard disks amountset /a totalhdam=0for /f "skip=9 tokens=2" %%a in ('echo list disk ^| diskpart.exe') do (  set /a totalhdam=!totalhdam!+1)::get innternal fixed hard disk amountset /a fixedhdam=%totalhdam%-%fixedusbam%::get internal hard disk drive letters and fixed usb drive lettersif %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 AFOR /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 pointFOR /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 lettersFOR /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 usbdiskset neworder=%fixdrv% %cdrom% %hdusb% %remusb%set fulldrv=CDEFGHIJKLMNOPQRSTUVWXYZfor %%a in (%virdrv%) do call set fulldrv=%%fulldrv:%%a=%%:: get ordered vidset /a n=0for %%a in (%neworder%) do (  if %%a neq %systemdrive:~0,1% (    for /f %%b in ('mountvol %%a: /l') do (    mountvol %%a: /dcall echo %%b %%fulldrv:~!n!,1%%: >>c.txt      set /a n+=1      )  ))for /f "tokens=1,2 delims= " %%a in (c.txt) do mountvol %%b %%adel c.txt

Attached Files


Edited by victor888, 01 November 2008 - 08:07 AM.



How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

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

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 OFFSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONFOR %%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 %%DCALL :Drivetype %%A %%D))SET First8SET FIXEDSET REMOVABLEPAUSEGOTO :EOF:DrivetypeSET DRIVE_%1=%2CALL 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, 13 October 2008 - 07:58 AM.


#3
victor888

victor888

    Member

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

#4
jaclaz

jaclaz

    The Finder

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

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
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
That is true.

hope your optimized version.

#6
bobob

bobob
  • Member
  • 2 posts
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
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
as long has the command fsutil, mountvol, diskpart and findstr exist, the batch does work.

#8
jaclaz

jaclaz

    The Finder

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

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

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, 16 October 2008 - 02:04 AM.


#9
bobob

bobob
  • Member
  • 2 posts

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
jaclaz

jaclaz

    The Finder

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

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
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
Jaclaz, check it again.

#12
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,391 posts
  • OS:none specified
  • Country: Country Flag
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
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
SCSI drive is concerned too.

Edited by victor888, 20 October 2008 - 09:34 PM.


#14
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,391 posts
  • OS:none specified
  • Country: Country Flag
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 Files


Edited by jaclaz, 22 October 2008 - 08:10 AM.


#15
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
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, 22 October 2008 - 09:38 AM.


#16
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
WMI is too powerful, most valuable link: http://www.windows-m...cal/#ADPPDD.htm

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

Edited by victor888, 27 October 2008 - 08:32 PM.


#17
jaclaz

jaclaz

    The Finder

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

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


Nice VBS script. :)

I'll try to replicate it's approach.

jaclaz

#18
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
Jaclaz go!

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

#19
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,391 posts
  • OS:none specified
  • Country: Country Flag
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 Files



#20
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
Very good example. I will study it asap.

#21
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,391 posts
  • OS:none specified
  • Country: Country Flag
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

Attached Files



#22
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
you make more progress in using wmic.
I will try to continue.

#23
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,391 posts
  • OS:none specified
  • Country: Country Flag
Almost, but not quite, completely unrelated ;)
symbol2mvol.cmd


Uses:
Listdosdevices:
http://www.uwe-siebe...ivetools_e.html

VLM (part of the DSFOK package):
http://members.ozema...eezip/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

Attached Files


Edited by jaclaz, 02 November 2008 - 06:29 AM.


#24
victor888

victor888

    Member

  • Member
  • PipPip
  • 155 posts
I found one more powerfull disk tool here: http://technet.micro...648(en-us).aspx

DiskExt v1.1 which gives each disk it mount volume and drive letters.

#25
jaclaz

jaclaz

    The Finder

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

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, 04 November 2008 - 10:33 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN