本帖最后由 pcl_test 于 2017-5-2 00:42 编辑
[已解决]如果有2个或者多个硬盘,如何判断每个硬盘是MBR分区还是GTP分区?- @echo off
-
- :IsGPT
- rem 判定是否是GPT磁盘。
- echo list disk >yiwuyun.txt
- for /f "skip=8 tokens=3 delims=B" %%k in ('diskpart /s yiwuyun.txt') do (
- set temp=%%k
- if "!temp:~8,1!"=="*" goto gpt
- )
- set gpt=false
- echo Your disk is MBR disk!
- ping 127.0.0.1 -n 5 >nul 2>nul
- goto nogpt
- :gpt
- set gpt=true
- echo Your disk is GPT disk!
- ping 127.0.0.1 -n 5 >nul 2>nul
- :nogpt
- if exist yiwuyun.txt del yiwuyun.txt || exit /b 1
- rem echo errorlevel is !errorlevel!
- exit /b 0
复制代码 最好能与下面的bat代码,合并下。
bat显示硬盘及分区容量。- @echo off
- del /q c:\diskinfo.* >nul 2>nul
-
- for /f "delims=:" %%i in ('findstr /n "^:DynamicScript$" "%~f0"') do (
- more +%%i "%~f0" > c:\diskinfo.vbs
- )
-
- ping 127.0.0.1 -n 2 >nul 2>nul
-
- echo ——————————————————————————————————————— >nul 2>nul
- start c:\diskinfo.vbs
- ping 127.0.0.1 -n 5 >nul 2>nul
-
- cls
- type c:\diskinfo.txt
-
- ping 127.0.0.1 -n 15 >nul 2>nul & del /q c:\diskinfo.* & exit/b
-
- goto :eof
-
-
-
- echo ——————————————————————————————————————— >nul 2>nul
- :DynamicScript
- Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
- Set colDisks = objWMI.ExecQuery("select * from Win32_DiskDrive where MediaType like 'fixed%'")
-
- For Each objDisk in colDisks
- i = i + 1
- s = s & "硬盘" & i & ":" & vbTab
- s = s & "大小:" & GetSize(objDisk.Size) & vbTab
- s = s & "型号:" & objDisk.Caption & vbCrLf
- strDiskID = Replace(objDisk.DeviceID, "\", "\\")
-
- Set colPartitions = objWMI.ExecQuery _
- ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strDiskID & """}" _
- & " where AssocClass=Win32_DiskDriveToDiskPartition")
-
- For Each objPartition in colPartitions
- strPartId = objPartition.DeviceID
-
- Set colLogicalDisks = objWMI.ExecQuery _
- ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & strPartId & """} where AssocClass=Win32_LogicalDiskToPartition")
-
- For Each objLogicalDisk in colLogicalDisks
- size = objLogicalDisk.Size
- free = objLogicalDisk.Freespace
- used = FormatNumber((size - free) / size * 100, 2, true) & "%"
- s = s & "分区" & objLogicalDisk.DeviceID & vbTab
- s = s & "大小:" & GetSize(size) & vbTab
- s = s & "剩余:" & GetSize(free) & vbTab
- s = s & "使用率:" & used & vbCrLf
- Next
- Next
- s = s & vbCrLf
- Next
-
- Set fso = CreateObject("Scripting.FileSystemObject")
- fso.OpenTextFile("c:\diskinfo.txt", 2, true).Write s
-
- Function GetSize(intSize)
- If intSize/1024/1024 > 1024 Then
- GetSize = FormatNumber(intSize/1024/1024/1024, 2, true) & "GB"
- Else
- Getize = FormatNumber(intSize/1024/1024, 2, true) & "MB"
- End If
- End Function
复制代码
|