test-1.bat- @echo off
- REM 设置待查看的盘符
- set "MyLetter=C:"
- 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 (
- for /f "delims=" %%i in ("%%b") do (
- if "%%a" equ "DiskIndex" (
- set "LD2DI=%%i"
- ) else if "%%a" equ "Index" (
- set "LD2I=%%i"
- )
- )
- )
- echo Disk #%LD2DI%, Partition #%LD2I%
- pause
复制代码 test-2.bat- @echo off
- REM 设置待查看的盘符
- set "MyLetter=C:"
- for /f "tokens=3 delims==" %%a in ('wmic path Win32_LogicalDiskToPartition.Dependent^="Win32_LogicalDisk.DeviceID='%MyLetter%'" get Antecedent /value') do (
- set "DeviceID=%%a"
- )
- set "LD2Position=%DeviceID:~1,-3%"
- echo,%LD2Position%
- pause
复制代码 test-3.bat- @echo off
- REM 查看系统盘符所在的硬盘和分区
- set "MyLetter=%SystemDrive%"
- for /f "tokens=3 delims==" %%a in ('wmic path Win32_LogicalDiskToPartition.Dependent^="Win32_LogicalDisk.DeviceID='%MyLetter%'" get Antecedent /value') do (
- set "DeviceID=%%a"
- )
- set "LD2Position=%DeviceID:~1,-3%"
- echo,%LD2Position%
- pause
复制代码 test-4.bat- @echo off
- REM 查看系统盘符所在的硬盘和分区
- for /f "tokens=2 delims==" %%i in ('wmic Partition where "BootPartition='true'" get DeviceID /value ^| find "="') do (
- for %%j in ("%%i") do (
- set "LD2Position=%%~j"
- )
- )
- echo,%LD2Position%
- pause
复制代码
|