[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

试试这个 for/f 一行流的结果...
  1. @echo off
  2. for /f tokens^=2^ delims^=^" %%2 in ('wmic logicaldisk where DeviceID^=^"d:^" assoc /assocclass:Win32_LogicalDiskToPartition') do set "v=%%2"
  3. echo,DeviceID = %v%
复制代码

TOP

test-1.bat
  1. @echo off
  2. REM 设置待查看的盘符
  3. set "MyLetter=C:"
  4. for /f "tokens=1-2 delims==" %%a in ('wmic LogicalDisk where "DeviceID='%MyLetter%'" assoc:value /resultclass:Win32_DiskPartition ^| findstr /b /c:"DiskIndex=" /c:"Index="') do (
  5.     for /f "delims=" %%i in ("%%b") do (
  6.         if "%%a" equ "DiskIndex" (
  7.             set "LD2DI=%%i"
  8.         ) else if "%%a" equ "Index" (
  9.             set "LD2I=%%i"
  10.         )
  11.     )
  12. )
  13. echo Disk #%LD2DI%, Partition #%LD2I%
  14. pause
复制代码
test-2.bat
  1. @echo off
  2. REM 设置待查看的盘符
  3. set "MyLetter=C:"
  4. for /f "tokens=3 delims==" %%a in ('wmic path Win32_LogicalDiskToPartition.Dependent^="Win32_LogicalDisk.DeviceID='%MyLetter%'" get Antecedent /value') do (
  5.     set "DeviceID=%%a"
  6. )
  7. set "LD2Position=%DeviceID:~1,-3%"
  8. echo,%LD2Position%
  9. pause
复制代码
test-3.bat
  1. @echo off
  2. REM 查看系统盘符所在的硬盘和分区
  3. set "MyLetter=%SystemDrive%"
  4. for /f "tokens=3 delims==" %%a in ('wmic path Win32_LogicalDiskToPartition.Dependent^="Win32_LogicalDisk.DeviceID='%MyLetter%'" get Antecedent /value') do (
  5.     set "DeviceID=%%a"
  6. )
  7. set "LD2Position=%DeviceID:~1,-3%"
  8. echo,%LD2Position%
  9. pause
复制代码
test-4.bat
  1. @echo off
  2. REM 查看系统盘符所在的硬盘和分区
  3. for /f "tokens=2 delims==" %%i in ('wmic Partition where "BootPartition='true'" get DeviceID /value ^| find "="') do (
  4.     for %%j in ("%%i") do (
  5.         set "LD2Position=%%~j"
  6.     )
  7. )
  8. echo,%LD2Position%
  9. pause
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表