用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
展开
 我来答
gavineaglechou
推荐于2016-01-30 · TA获得超过157个赞
知道小有建树答主
回答量:133
采纳率:0%
帮助的人:131万
展开全部
楼主,你好,你的原代码格式有问题,我帮你改了,你试试下边的代码

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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式