开发者

calculate free space of C drive using vbscript

how can i write vbscript that calculates the free space in C: drive of a windows开发者_StackOverflow中文版 machine


have a look at this page:

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


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


Use the FileSystemObject The page includes an JScript example

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);
}


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜