本帖最后由 ygqiang 于 2014-12-17 00:26 编辑
[已解决]通过bat批处理文件,生成下面这个vbs代码文件。哪些地方,需要注意加上特殊符号?
比如echo i = i + ^1>>c:\diskpart.vbs- 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:\diskpart.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
复制代码
|