本帖最后由 pcl_test 于 2017-5-1 23:55 编辑
回复 19# 飛雪
vbs- Set ws = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- If LCase(Right(WSH.FullName, 11)) = "wscript.exe" Then
- ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 0
- WSH.Quit
- End If
-
- Dim arr()
- Set oExec = ws.Exec("cmd /c ""(echo;list disk|diskpart)|findstr /irc:""[0-9][0-9]* *[tgmk]b"" "" ")
-
- Do While oExec.StdOut.AtEndOfStream <> true
- str = Trim(oExec.StdOut.ReadLine)
- num = CInt(Split(str, " ")(1))
- ReDim Preserve arr(num)
- If InStrRev(str, "*") >0 Then
- arr(num) = "GPT"
- Else
- arr(num) = "MBR"
- End If
- Loop
-
- Dim objWMI, colDisks
- Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
- Set colDisks = objWMI.ExecQuery("select * from Win32_DiskDrive where MediaType like 'fixed%'")
- For Each objDisk in colDisks
- s = s & "硬盘" & objDisk.Index & ":" & vbTab
- s = s & "大小:" & GetSize(objDisk.Size) & vbTab
- s = s & "型号:" & objDisk.Caption & vbTab
- s = s & "分区表:" & arr(CInt(objDisk.Index)) & 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
- Msgbox s
-
-
- Function GetSize(intSize)
- If intSize/1024/1024 > 1024 Then
- GetSize = FormatNumber(intSize/1024/1024/1024, 2, true) & "GB"
- Else
- GetSize = FormatNumber(intSize/1024/1024, 2, true) & "MB"
- End If
- End Function
复制代码
|