troubleshooting Question

Checking disk space errors vbscript

Avatar of martin05
martin05 asked on
Visual Basic ClassicVB Script
7 Comments1 Solution265 ViewsLast Modified:
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


ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 7 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 7 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004