『楼 主』:
[08年11月3日更新]新版解决盘符错乱批处理
只要有热心朋友的参与,这个脚本肯定会做到最好!BEST GOING......
==
在此感谢MSFN论坛的JACLAZ和CN-DOS的顶级批处理高手的指点!
本次更新,在NT系统下,接近最终更新了。
代码优化,执行效率更高,对于盘符顺序正确的盘,不再删除盘符。
不论多少硬盘,多少虚拟盘,多少USB盘,多少光盘,此程序都会正确排列盘符顺序的。
本程序就是用于解决盘符错乱的,运行于NT系统,暂不适用于VISTA系统(因为VISTA下的DISKPART命令与XP不同)。无论是启动PE盘符错乱,还是使用USB盘安装XP使盘符错乱,运行一下此批处理,都正常了。
1:运行本程序,请将其放到系统盘运行;
2:运行此程序时,请关闭非系统盘打开的任何程序及文件,如果有安装到非系统盘的程序,则由于重排盘符,如果原来盘符就错乱的话,则有可能使程序指向出错,此种情况建议不要运行此程序。
3:在PE下运行此程序,请将其和这几个工具find.exe(有的PE竟然连这个也给精简了), fsutil, mountvol, diskpart,findstr.exe放到一块运行,这几个程序可以从XP系统的windows\system32目录获得。
本程序不会弄丢你的任何东西,如果运行失败,可以通过磁盘管理手动添加更改盘符。
MSFN英文讨论及链接:http://www.msfn.org/board/compatible-batch-file-o-t124539.html。
::created by VICTOR888, thanks to jaclaz in MSFN forum and batch experts in cn-dos forum
::revised on Nov 3, 2008
::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
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,2 delims=-" %%b IN ('fsutil fsinfo drivetype !dr!:') DO (
set cr=%%c
set cr=!cr:~1,2!
if "!cr!" equ "CD" (
SET vname=%%b
SET vname=!vname:~0,1!
for /f %%x in ('mountvol !vname!: /l ^| find "\\"') do call set dvdrom=%%dvdrom%% %%vname%%
)
if "!cr!" equ "可移" (
set /a remusbam=!remusbam!+1
SET vname=%%b
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%
::ordering drive letters by internal fixed hard disk, cdrom, hard usb disk and removalbe usbdisk
set neworder=%fixdrv% %dvdrom% %hdusb% %remusb%
call set neworder=%%neworder:%systemdrive:~0,1%=%%
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 (
call :done %%a %%fulldrv:~!n!,1%%
set /a n+=1
)
if exist "c.txt" (
for /f "tokens=1,2 delims= " %%a in (c.txt) do mountvol %%b %%a
del c.txt
)
goto :eof
:done
if %1 neq %2 (
for /f %%b in ('mountvol %1: /l') do echo %%b %2: >>c.txt
mountvol %1: /d
)
goto :eof 下载:http://upload.cn-dos.net/img/1048.rar
[ Last edited by victor888 on 2008-11-3 at 11:13 ]
|