Board logo

标题: [系统相关] [分享]批处理修正盘符 [打印本页]

作者: hfg1977    时间: 2011-5-7 15:16     标题: [分享]批处理修正盘符

在安装数个硬盘的情况下有时会产生盘符交叉问题, 特写此P

注:盘符 卷标 与 卷 是不同的感念,不要混淆.
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if "%~1"=="" (
  4. call copy "%~0" "%windir%.\..\"
  5. start "" "%windir%.\..\%~nx0" %~dp0
  6. exit /b
  7. )
  8. set "oldPath=%*"
  9. echo 工作路径1:%oldPath%
  10. echo 工作路径:%~dp0
  11. echo.======== Ver:1.0 ==================== 发布日期: 2010-09-07 ==============
  12. echo. · 1. 自动
  13. echo. · 2. 根据Volume.txt的顺序修改盘符
  14. echo.====================== Copyright@ by hf-g 2010-09-07 [彭城] =============
  15. set "choice="&set/p choice=输入你的选择(1/2/q):
  16. if /i "%choice%"=="q" goto end
  17. echo %choice%|findstr "^[12]$">nul 2>nul&&goto choice%choice%
  18. goto end
  19. ::==============================================================
  20. :choice1
  21. ::备份及查找各硬盘分区卷的装入点
  22. cd.>Volume_old.txt
  23. for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
  24. set var=%%i
  25. set drive=!var:~-2!
  26. fsutil fsinfo drivetype !drive!|find "固定">nul && (for /f "delims= " %%a in ('mountvol !drive! /l') do set "%%a=1" & echo !drive! %%a>>Volume_old.txt)
  27. )
  28. ::根据不同硬盘的枚举顺序修改盘符,跳过C:盘
  29. if not exist Volume.txt (mountvol|findstr "\\\\\?\\Volume">Volume.txt)
  30. set "char=DEFGHIJKLMNOPQRSTUVWXYZ"
  31. @echo on
  32. set/a count=0
  33. for /f "skip=1 usebackq delims= " %%a in ("Volume.txt") do (
  34. call echo !%%a! ++ +%%char:~!count!,1%%+
  35. if "!%%a!"=="1" (call mountvol %%char:~!count!,1%%: /d & call mountvol %%char:~!count!,1%%: %%a & set/a count+=1)
  36. )
  37. @echo off
  38. goto:eof
  39. ::==============================================================
  40. :choice2
  41. ::根据Volume.txt的顺序修改盘符,跳过C:盘
  42. if not exist Volume.txt (mountvol|findstr "\\\\\?\\Volume">Volume.txt)
  43. ::生成Volume_320.txt文件,并删除盘符(跳过C:盘).
  44. cd.>Volume_320.txt
  45. for /f %%a in ('mountvol^|findstr "\\\\\?\\Volume :\\"') do (
  46. set "Volume=%%a"
  47. if "!Volume:~-2!"==":\" (
  48. if /i not "%%a"=="%SystemDrive%\" mountvol !Volume:~0,2! /d
  49. call set "Volume_!count!=!Volume:~0,2! %%Volume_!count!%%"
  50. ) else (
  51. set/a num+=1
  52. set "count=00!num!"
  53. set "count=!count:~-3!"
  54. set "Volume_!count!= %%a"
  55. ))
  56. set Volume_
  57. for /f "tokens=2 delims==" %%a in ('set Volume_') do echo %%a>>Volume_320.txt
  58. @echo on
  59. set /p "Volfile=输入已设定好的Volume文件:"
  60. if not defined Volfile (set "Volfile=Volume_320.txt")
  61. copy "%oldPath%.\%Volfile%" "%windir%.\..\"
  62. for /f "tokens=1,2 usebackq delims= " %%a in ("%Volfile%") do (
  63. if /i not "%%a"=="%SystemDrive%" (
  64. call echo +%%a+ ++ +%%b+
  65. call mountvol %%a %%b
  66. ))
  67. @echo off
  68. ::==============================================================
  69. pause
  70. pause
  71. :end
  72. goto:eof
  73. ::==============================================================
复制代码

作者: hfg1977    时间: 2011-5-7 15:21

卷的信息,每次做系统(安装或GHOST),都是不同的,哪怕是同个gho文件且硬件未有任何变动的情况下.
所以备份卷的信息没有任何意义.
作者: yjstone    时间: 2011-5-8 16:22

for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do .......这句代码在win7下不能正常工作,命令
fsutil fsinfo drives|find /v "" 在win7是这样显示的,跟XP和2003的不一样:
作者: Batcher    时间: 2011-5-8 16:40

Vista跟Win7比较象:
C:\Test>fsutil fsinfo drives|find /v ""

Drives: C:\ D:\ S:\

作者: hfg1977    时间: 2011-5-8 18:03

哦, Vista跟Win7是单行显示的呀!
修改以下可以了:
  1. call:isWindowsVer
  2. for /f "delims=\" %%i in ('if "%isXPlevel%"^=^="1" ^(fsutil fsinfo drives^|find /v ""^) else ^(for /f %%m in ^('fsutil fsinfo drives^^^|find /v ""'^) do echo %%m^)') do (
复制代码
  1. ::================= 判断Windows版本 ============================
  2. ::返回值: isXPlevel=1 XP级别;isXPlevel=2 高于XP级别;isXPlevel=0 低于XP级别
  3. :isWindowsVer
  4. ver|findstr "5\.[0-9]\.[0-9][0-9]*">nul&&(set isXPlevel=1&goto:eof)
  5. ver|findstr "6\.[0-9]\.[0-9][0-9]*">nul&&(set isXPlevel=2&goto:eof)
  6. set isXPlevel=0
  7. goto:eof
复制代码

作者: CrLf    时间: 2011-5-8 18:08

wmic和fsutil在不同系统的表现不同,前阵子忽然醒悟获取盘符其实还可以用mountvol
  1. for /f %%a in ('mountvol^|find ":\"') do echo %%a
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2