用VBS脚本获取硬盘信息
下面是一段代码但编译不过,请帮我改一下,谢谢了!Setfsoobj=CreateObject("Scripting.FileSystemObject")DriversIn...
下面是一段代码但编译不过,请帮我改一下,谢谢了!
Set fsoobj = CreateObject("Scripting.FileSystemObject")
DriversInfo = GetDriversInfo
DriversInfo = Replace(DriversInfo, "|", vbCrLf)
sReturn ="硬盘信息:" & vbCrLf & DriversInfo
Wscript.Echo sReturn
Function GetDriversInfo() GetDriversInfo = ""
Set drvObj = fsoobj.Drives
For Each D In drvObj
Err.Clear
If D.DriveLetter <> "A" Then If D.isReady Then GetDriversInfo = GetDriversInfo & "分区:" & D.DriveLetter & vbCrLf
GetDriversInfo = GetDriversInfo & "可用空间:" & cSize(D.FreeSpace) & vbCrLf
GetDriversInfo = GetDriversInfo & "总大小:" & cSize( D.TotalSize) & vbCrLf
GetDriversInfo = GetDriversInfo & "使用率 :" & (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &"%" & vbCrLf
GetDriversInfo = GetDriversInfo & "|"
ElseEndIfElseEndIfNextEndFunctionFunction cSize(tSize)
If tSize >= 1073741824 Then cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
ElseIf tSize >= 1048576 Then cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB" ElseIf tSize >= 1024 Then cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"Else cSize = tSize & "B"EndIfEndFunction 展开
Set fsoobj = CreateObject("Scripting.FileSystemObject")
DriversInfo = GetDriversInfo
DriversInfo = Replace(DriversInfo, "|", vbCrLf)
sReturn ="硬盘信息:" & vbCrLf & DriversInfo
Wscript.Echo sReturn
Function GetDriversInfo() GetDriversInfo = ""
Set drvObj = fsoobj.Drives
For Each D In drvObj
Err.Clear
If D.DriveLetter <> "A" Then If D.isReady Then GetDriversInfo = GetDriversInfo & "分区:" & D.DriveLetter & vbCrLf
GetDriversInfo = GetDriversInfo & "可用空间:" & cSize(D.FreeSpace) & vbCrLf
GetDriversInfo = GetDriversInfo & "总大小:" & cSize( D.TotalSize) & vbCrLf
GetDriversInfo = GetDriversInfo & "使用率 :" & (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &"%" & vbCrLf
GetDriversInfo = GetDriversInfo & "|"
ElseEndIfElseEndIfNextEndFunctionFunction cSize(tSize)
If tSize >= 1073741824 Then cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
ElseIf tSize >= 1048576 Then cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB" ElseIf tSize >= 1024 Then cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"Else cSize = tSize & "B"EndIfEndFunction 展开
展开全部
楼主,你好,你的原代码格式有问题,我帮你改了,你试试下边的代码
Set fsoobj = CreateObject("Scripting.FileSystemObject")
DriversInfo = GetDriversInfo
DriversInfo = Replace(DriversInfo, "|", vbCrLf)
sReturn ="硬盘信息:" & vbCrLf & DriversInfo
Wscript.Echo sReturn
Function GetDriversInfo()
GetDriversInfo = ""
Set drvObj = fsoobj.Drives
For Each D In drvObj
Err.Clear
If D.DriveLetter <> "A" Then
If D.isReady Then
GetDriversInfo = GetDriversInfo & "分区:" & D.DriveLetter & vbCrLf
GetDriversInfo = GetDriversInfo & "可用空间:" & cSize(D.FreeSpace) & vbCrLf
GetDriversInfo = GetDriversInfo & "总大小:" & cSize( D.TotalSize) & vbCrLf
GetDriversInfo = GetDriversInfo & "使用率 :" & (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &"%" & vbCrLf
GetDriversInfo = GetDriversInfo & "|"
Else
End If
Else
End If
Next
End Function
Function cSize(tSize)
If tSize >= 1073741824 Then
cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
ElseIf tSize >= 1048576 Then
cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB"
ElseIf tSize >= 1024 Then
cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"
Else cSize = tSize & "B"
End If
End Function
Set fsoobj = CreateObject("Scripting.FileSystemObject")
DriversInfo = GetDriversInfo
DriversInfo = Replace(DriversInfo, "|", vbCrLf)
sReturn ="硬盘信息:" & vbCrLf & DriversInfo
Wscript.Echo sReturn
Function GetDriversInfo()
GetDriversInfo = ""
Set drvObj = fsoobj.Drives
For Each D In drvObj
Err.Clear
If D.DriveLetter <> "A" Then
If D.isReady Then
GetDriversInfo = GetDriversInfo & "分区:" & D.DriveLetter & vbCrLf
GetDriversInfo = GetDriversInfo & "可用空间:" & cSize(D.FreeSpace) & vbCrLf
GetDriversInfo = GetDriversInfo & "总大小:" & cSize( D.TotalSize) & vbCrLf
GetDriversInfo = GetDriversInfo & "使用率 :" & (100*((D.TotalSize-D.FreeSpace)/D.TotalSize)) &"%" & vbCrLf
GetDriversInfo = GetDriversInfo & "|"
Else
End If
Else
End If
Next
End Function
Function cSize(tSize)
If tSize >= 1073741824 Then
cSize = Int((tSize / 1073741824) * 1000) / 1000 & " GB"
ElseIf tSize >= 1048576 Then
cSize = Int((tSize / 1048576) * 1000) / 1000 & " MB"
ElseIf tSize >= 1024 Then
cSize = Int((tSize / 1024) * 1000) / 1000 & " KB"
Else cSize = tSize & "B"
End If
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询