list all windows user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emooo
    New Member
    • Aug 2008
    • 2

    list all windows user

    Hello

    I try to list all windows user using this code but it throws exception of invalid query , I am using win vista.

    the code:
    Code:
    try
                    {
                        SelectQuery sQuery = new SelectQuery("Win32_UserAccount","Domain=’ALI-PC’");
                        ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);
                       // String[] winUsers = null;
                        int i = 0;
                        foreach (ManagementObject mObject in mSearcher.Get())
                        {
                          //  winUsers[i] = ((String)mObject["Name"]);
                          //  MessageBox.Show(winUsers[i]);
                            i++;
    
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
    can some one help me?
    Last edited by Curtis Rutland; Oct 30 '08, 03:24 PM. Reason: added [code] tags
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    Also, try to remember that whitespace is preserved inside code tags, so indent properly.

    MODERATOR

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Does changing your SelectQuery to:

      SelectQuery sQuery = new SelectQuery("Wi n32_UserAccount ");

      Fix anything?
      Since you're looping through the result anyways you could filter your search at that point...


      You could also try using an SQL Where clause:

      SelectQuery sQuery = new SelectQuery("Se lect * From Win32_UserAccou nt Where Domain=’ALI-PC’");

      You could look into using the DirectorySearch er Class to search and perform queries against an Active Directory Domain Services.

      Also, check out this article. It may help.

      -Frinny

      Comment

      Working...