Hi
I have a little bit of VB which checks diskspace
Sub chkdiskspace (StrComp)
If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking disk space...</font><br>"
l.writeline Time & " - Checking disk space."
'==Connect to winmgmts==
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrComp & "\root\cimv2")
'==Run query to identify logical disks==
Set colDisks = objWMIService.ExecQuery _
("Select Freespace, Name, Size from Win32_LogicalDisk where DriveType = 3")
Call fctErrorHandling
'==Write header to htm file==
res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=200>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Disk space</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Disk ID</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Percentage Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Total Space</font></th>")
res.Writeline ("</tr>")
'==Write results to htm file==
For Each objDisk In colDisks
Call bgcolor
res.Writeline ("<TR bgcolor='" & strbgcolor & "'><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & objDisk.Name & strendline)
If (objDisk.Freespace/objDisk.Size)*100 <=10 Then
fontcol = "#FF0000"
Else
fontcol = "#666666"
End If
If objDisk.Freespace > 10000 Then
strUnit = "GB"
strDiskSize = FormatNumber(objDisk.Freespace / 1073741824,2)
strDiskTotal = FormatNumber(objDisk.Size / 1073741824,2)
ElseIf objDisk.Freespace < 1 Then
strUnit = "KB"
strDiskSize = FormatNumber(objDisk.Freespace / 1024,2)
strDiskTotal = FormatNumber(objDisk.Size / 1024,2)
ElseIf objDisk.Freespace < 1000 Then
strUnit = "MB"
strDiskSize = FormatNumber(objDisk.Freespace/1048576,2)
strDiskTotal = FormatNumber(objDisk.Size / 1048576,2)
End If
strPercentFree = Round((objDisk.Freespace/objDisk.Size)*100,2)
If strPercentFree < intFreeSpaceThreshold Then
'wscript.echo strPercentFree
strSpace = strSpace & objDisk.Name & " - " & Round((objDisk.Freespace/objDisk.Size)*100,2) _
& "% free (" & FormatNumber(objDisk.Freespace / 1073741824,2) & "Gb remaining)<br>"
res.Writeline ("<TD><font face=" & strFontStyle & " color='red' size=1>" & strPercentFree & "%" & strendline)
blnErrors = True
blnDiskSpace = True
Else
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strPercentFree & "%" & strendline)
End If
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskSize & strUnit & strendline)
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskTotal & strUnit & strendline & "</TR>")
Next
the problem i have is I need to omit some drives from the check as they are returning NULL values
can anyone see from the code an easy way to do it ?
thanks
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.