使用vbscript计算C盘的可用空间

时间:2010-05-25 08:45:58

标签: vbscript

如何编写用于计算Windows机器的C:驱动器中的可用空间的vbscript

4 个答案:

答案 0 :(得分:8)

Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive("C:")
WScript.Echo d.FreeSpace

答案 1 :(得分:6)

查看this page

Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
Wscript.Echo objLogicalDisk.FreeSpace

答案 2 :(得分:1)

使用FileSystemObject该页面包含一个JScript示例

function ShowDriveInfo1(drvPath)
{
   var fso, drv, s ="";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   drv = fso.GetDrive(fso.GetDriveName(drvPath));
   s += "Drive " + drvPath.toUpperCase()+ " - ";
   s += drv.VolumeName + "<br>";
   s += "Total Space: " + drv.TotalSize / 1024;
   s += " Kb" + "<br>"; 
   s += "Free Space: " + drv.FreeSpace / 1024;
   s += " Kb" + "<br>";
   Response.Write(s);
}

答案 3 :(得分:0)

strComputer = "." 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_LogicalDisk where DeviceID='c:'",,48) 

For Each objItem in colItems 

if len(objItem.VolumeName)>0 then

Wscript.Echo "-----------------------------------" & vbCrLf _
        & "VolumeName:" & vbTab & objItem.VolumeName  & vbCrLf _
        & "-----------------------------------" & vbCrLf _
        & "FreeSpace:" & vbTab _
        & FormatNumber((CDbl(objItem.FreeSpace)/1024/1024/1024))  & vbCrLf _
        & "Size:" & vbTab & vbTab _
        & FormatNumber((CDbl(objItem.Size)/1024/1024/1024))  & vbCrLf _
        & "Occupied Space:" & vbTab _
        & FormatNumber((CDbl(objItem.Size - objItem.FreeSpace)/1024/1024/1024)) 
   end if
Next