Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Sometimes I really hate WMI

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59271
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Sometimes I really hate WMI
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Sometimes I really hate WMI - 4/17/2008 9:23:41 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Here's an annoying little WMI quirk I came across today.

Take these two scripts

Listing 1


      

Listing 2



      

Now, which one do you think would take the longest?  You'd suppose Listing 1 right because the query in Listing 2 is even more limiting.  Well, you'd be wrong!  I can only assume that, whatever reason, with Listing 2 it queries every entry to see if the Name matches and THEN checks to see if LocalAccount = True

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
 
 
Post #: 1
 
 RE: Sometimes I really hate WMI - 4/18/2008 12:23:42 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I queried my laptop (vista) and my other box (winxp) and Listing 2 is the same or faster than listing 1.  Maybe if you show us how you measured the difference in speed I can try that. 

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 2
 
 RE: Sometimes I really hate WMI - 4/18/2008 12:25:04 AM   
  TNO


Posts: 1247
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
You could probably think of it like this:

Dim Table : Table = Win32_UserAccount

For Each Name in Table
If LocalAccount = True Then
'Add to collection
End If
Next

For Each SID in Table
If (LocalAccount = True) AND (Name='Administrator') Then
'Add to collection
End If
Next

At least that's how I imagine it occurring.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ginolard)
 
 
Post #: 3
 
 RE: Sometimes I really hate WMI - 4/18/2008 5:02:49 AM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
I just ran both scripts in Primalscript.  Listing 1 came back with results almost immediately.  Listing 2 sat there for about 30 seconds before I cancelled it.

Of course, now that I run it on my PC here at home there is little to no difference in the speed.  I wonder if it's only on machines in an AD domain that it has this issue?

< Message edited by ginolard -- 4/18/2008 5:04:51 AM >


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to TNO)
 
 
Post #: 4
 
 RE: Sometimes I really hate WMI - 4/18/2008 6:49:38 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I ran both in PrimalScript at home when I first posted....I just tried it in PrimalScript at work and see what you mean.

Maybe it is just a problem when you search on name since searching by SID is almost as fast....

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT SID,Name FROM Win32_UserAccount where LocalAccount=True AND SID LIKE 'S-1-5-%-500'")

UPDATE:

quote:


Note  Because both the Name and Domain are key properties, enumerating Win32_UserAccount on a large network can affect performance negatively. Calling GetObject or querying for a specific instance has less impact.


After reading this I tried the following which was almost as fast as the first one....


      

< Message edited by dm_4ever -- 4/18/2008 6:55:32 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 5
 
 RE: Sometimes I really hate WMI - 4/18/2008 7:17:10 AM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Hmm, OK, maybe I'll try that.  I can't query for a specific SID because I don't know the SID I want, that's the point.  I need to get the SID of the logged on user (of remote machines)  That's easy enough if it's a domain user, I can just can get it from AD but this seems the best way to get it for local users.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to dm_4ever)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Sometimes I really hate WMI Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts