BAT 显示磁盘详细信息
1.简介:
windows bash脚本,保存文本重命名后缀为xxx.bat,双击运行即可
' 2>nul 3>nul&cls&@echo off
'&title Disk partition capacity information
'&cscript -nologo -e:vbscript "%~f0"
'&pause&exit
On Error Resume Next
Set fso=CreateObject("Scripting.Filesystemobject")
Set ws=CreateObject("WScript.Shell")
Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set query1=wmi.ExecQuery("Select * from Win32_DiskDrive")
For Each item1 in query1
WSH.echo "Caption=" & item1.Caption
WSH.echo "DeviceID=" & item1.DeviceID
WSH.echo "InterfaceType=" & item1.InterfaceType
WSH.echo "MediaType=" & item1.MediaType
WSH.echo "Size=" & SizeFormat(item1.Size)
WSH.echo "=================================================================================================================="
index=item1.Index
If index <> "" Then
Set query2=wmi.ExecQuery("Select * from Win32_LogicalDiskToPartition")
For Each item2 in query2
If InStr(item2.Antecedent, "Disk #" & index & ",") >0 Then
drive=replace(split(item2.Dependent,"=")(1), """", "")
If drive <> "" Then
Set query3=wmi.ExecQuery("Select * from Win32_LogicalDisk where Caption='" & drive & "'")
For Each item3 in query3
line=""
line=line & item3.Caption & " | "
line=line & item3.Description & " | "
line=line & item3.FileSystem & " | "
line=line &"Total:"& SizeFormat(item3.Size) & " | "
line=line & " Available:"& SizeFormat(item3.FreeSpace) & " | "
line=line &"Used capacity:"& SizeFormat(item3.Size - item3.FreeSpace) & " | "
line=line & "Usage rate:"& FormatNumber((item3.Size - item3.FreeSpace) / item3.Size, 2, true) * 100 & "%"
rem echo Disk letter | Disk type | Partition format | Total capacity | Available capacity | Used capacity | Capacity usage
WSH.echo line
Next
End If
End If
Next
End If
WSH.echo ""
Next
Function SizeFormat(size)
If size >= 1099511627776 Then
SizeFormat = FormatNumber(size/1099511627776, 2, true) & " TB"
ElseIf size >= 1073741824 Then
SizeFormat = FormatNumber(size/1073741824, 2, true) & " GB"
ElseIf size >= 1048576 Then
SizeFormat = FormatNumber(size/1048576, 2, true) & " MB"
ElseIf size >= 1024 Then
SizeFormat = FormatNumber(size/1024, 2, true) & " KB"
Else
SizeFormat = size & "B"
End If
End Function