• Status: Open
  • Priority: Medium
  • Security: Public
  • Views: 60
  • Last Modified:

WMI command is not returning a current value.

On a set of Windows 2012 servers, i check disk space every day.  

In a vb script, using this statement - (excerpt)

objSWbemServices.ExecQuery _
          ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

      For Each objDisk in colDisks

If Not IsNull(objDisk.FreeSpace) Then
                intVal = CDbl(objDisk.FreeSpace)

Without any changes to my knowledge to server security (using logon account), this vb script would work fine.  So lately within the last few days, (note that the script runs without any error), i can execute it and it creates the WMI object.  But now each day, the hard disk value does not change from day to day.  The intVal value of free disk space stays the same on each day it is run.  Where do I start to analyse?

Barry Lysy
Barry Lysy
QlemoBatchelor and DeveloperCommented:
You need to show more of your code, above does not allow to tell anything, as the lines are not connected, so all we could do is guessing.
Shaun VermaakTechnical Specialist/DeveloperCommented:
Why is
If Not IsNull(objDisk.FreeSpace) Then
                intVal = CDbl(objDisk.FreeSpace)

Open in new window

not in the loop
      For Each objDisk in colDisks

Open in new window

Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
I'm canceling this question.  I have  found the root cause. Sorry to be a bother.
We are also interested what was the cause.

Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
My root cause understanding was incorrect thinking that it was security related.  I tested using a different user's account where that account has local admin priv.  Using that account also returned the same result.  A server reboot looked as though it fixed the issue, but the issue reappeared.  Here is the complete vb script that i use... (also see more comments after the code block.)
Const HARD_DISK = 3
Dim intVal
Dim strUserName 
Dim strPassword 
Dim strMachineName
Dim objTextFile
Dim strDateTime

Set objFSO = CreateObject("Scripting.FileSystemObject")
strDomain = "" 

strUser = ""
strPassword = ""

strComputer = ""

WScript.Echo strComputer

getDiskSpace strComputer

Sub getDiskSpace(strComputer)
    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
                                                     "Root\CIMv2", _
                                                     strUser, _
                                                     strPassword, _
                                                     "MS_409", _
                                                     "ntlmdomain:" + strDomain)
    Set colDisks = objSWbemServices.ExecQuery _
        ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

    For Each objDisk in colDisks

        If Not IsNull(objDisk.FreeSpace) Then
            intVal = CDbl(objDisk.FreeSpace)
            strDeviceId = objDisk.DeviceID 
            intVal = CDbl(objDisk.FreeSpace / 1024 / 1024)
            intVal_2 = intVal* .001
            intVal_3 = FormatNumber(intVal_2,3)
            WScript.Echo strDeviceId, " ", intVal_3
     End if

End Sub

 I have been looking into  using WBEMTEST but dont know what to test from within that tool.  Because the script, actually runs and returns free disk space then that suggests permission to use wbem object is fine.  It appears that wbem is an older technology and not much out there for documentation that is current from MS.

Join & Write a Comment

Featured Post

Simple Misconfiguration =Network Vulnerability

In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now