• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 94
  • 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
           ....
        Next
.......

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?

thanks
0
Barry Lysy
Asked:
Barry Lysy
1 Solution
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
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
           ....
        Next
.......

Open in new window

?
0
 
Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
I'm canceling this question.  I have  found the root cause. Sorry to be a bother.
0
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

 
pcelbaCommented:
We are also interested what was the cause.

TIA
0
 
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
     
    Next

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.
0
 
Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
No replys to my latest post.  Please close this question.
0
 
Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
No one has replied so i wish to close this question.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
And in your closing answer If Not IsNull(objDisk.FreeSpace) Then is in the loop...
0
 
Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
thank you for your feedback Shaun.  I didnt quite understand what your point is in your remark "Not IsNull(objDisk.FreeSpace) Then is in the loop..."
0
 
Barry LysyApplication Systems Analyst / ProgrammerAuthor Commented:
What kind of a solution is this??  this is not a solution as it does nothing to fix the issue !!
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Your comment is still marked as solution

My comment is not meant to be a solution, only an observation. My point is that you posted broken code with your question, the command is not in the loop, which I queried. In your second comment, the command is in the loop
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

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