views:

20

answers:

1

I'm using following two WMI queries :

SELECT * FROM Win32_Group WHERE LocalAccount=true
SELECT Domain,Name FROM Win32_UserAccount WHERE LocalAccount=true

The 2nd query takes about 6 seconds to run (over only 4 users) whereas the 1st query takes about .3 seconds to run over 22 groups. Can somebody tell me why is there such a performance gap? And any alternative way to write the 2nd query?

EDIT:I'm running the query on a local machine, so connections should not come into the picture.

A: 

I assume that the second query is slow because it first has to retrieve all domain users. If you are only interested in local users anyway you can try the method described here or limit the query to the local machine:

public static void GetUsers()  
{  
    SelectQuery sQry = new SelectQuery(“Win32_UserAccount”,“Domain=’PCNAME’”);  

    try  
    {  
        ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQry); 

        Console.WriteLine(“User Accounts\n”);  

        foreach (ManagementObject mObject in mSearcher.Get())  
        {  
            Console.WriteLine(mObject[“Name”]);  
        }  
    }  
    catch (Exception ex)  
    {  
        Console.WriteLine(ex.ToString());  
    }       
} 
0xA3
Then why does the 1st query run so fast? Both check for local accounts only.
apoorv020
@apoorv020: I don't know for sure but I would assume that this has to do with the way groups are propagated to the hosts of a domain network.
0xA3
I checked out your query and they both have same timing(no luck.) I also tried Win32_account where LocalAccount=true and sidType=1.
apoorv020