Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI query delay

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
Here's a snippet of code:
Code:
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
    wscript.echo " Set colItems called"
    For Each objItem In colItems
        if objItem.Description = "Local Fixed Disk" then
            strHDDriveLetter = objItem.DeviceID
            strHDSize = CInt(objItem.Size / 1024 / 1024 / 1024)
            strHDFreeSpace = CLng(objItem.FreeSpace / 1024 / 1024)
'            strHDFreeSpace = objItem.FreeSpace

            WScript.Echo " Drive Letter: " & vbTAB & vbTAB & strHDDriveLetter
            WScript.Echo " Size: " & vbTAB & vbTAB & vbTAB & strHDSize & "Gb"
            'if strHDFreeSpace < 1000 then
            wscript.echo " Free Space: " & vbTAB & vbTAB & strHDFreeSpace & "Mb"
            'Else
            '    strHDFreeSpace =  CInt(strHDFreeSpace / 1024)
            '    wscript.echo " Free Space: " & vbTAB & vbTAB & strHDFreeSpace & "Gb"
            'End if
            objInventoryFile.write "HDD," & strHDDriveLetter & "," & strHDSize & "," & strHDFreeSpace & ",4,5,6,7,8,9,10" & vbCrLf
        end if
    Next
My question is, why is there a delay (of about 34 secs) between
Code:
wscript.echo " Set colItems called"
and
Code:
For Each objItem In colItems
It's all a bit odd really. I've got similar code at other places in my script, such as
Code:
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_CDROMDrive", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems
        strCDCaption = objItem.Caption
which produce no delays at all.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
The WMI query should populate the infos for all the logical drives, thus the delay.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, but there's only one logical drive...

If I put the line
Code:
objInventoryFile.write
after the 'End If' I get the C: drive reported on 12 times:
Code:
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
HDD	C:	75	8169
So I guess that explains the delay, so why is it iterating 12 times?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
why is it iterating 12 times
Replace this:
objInventoryFile.write "HDD," & strHDDriveLetter
with this:
objInventoryFile.write "HDD," & objItem.DeviceID
to discover why ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ah, right, Win32_LogicalDisk querys all (available) disk drives including mapped network drives.

So, is there a way of getting it to only query Local Fixed Disks BEFORE
Code:
For Each objItem In colItems

I can't find a class that only deals with local partitions AND provides the data I'm after.

Is there a way of getting it by changing the * in
Code:
SELECT * FROM Win32_LogicalDisk
I've yet to find out how to use other wildcards or specific criteria between the SELECT and FROM...

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Perhaps this ?
Code:
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk" _
 & " WHERE Description='Local Fixed Disk'" _
 , "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Looked good, although it produces and error:
Code:
 HARD DISK(S)
 ============
 Set colItems called
 P:\Scripts\Inventory_v1.02b.vbs(298, 5) (null): 0x80041018
where (298, 5) is
Code:
For Each objItem In colItems

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Typo on my part. It seems to be working now!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
...but it's still taking over 30 seconds because it still has to iterate through every drive to test if it's a 'Local fixed disk' or not...

Downer.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top