How to get all user account info in C# (windows VISTA/7)?

This is a discussion on How to get all user account info in C# (windows VISTA/7)? within the C# Programming forums, part of the General Programming Boards category; Hey guys, is there a way to get the information (username, home directory, user group, ...) from every user account ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    5

    How to get all user account info in C# (windows VISTA/7)?

    Hey guys,

    is there a way to get the information (username, home directory, user group, ...) from every user account on a windows machine (VISTA / 7). I'm running the program as an Administrator so rights shouldn't be a problem.

    Ofcourse the passwords aren't needed.

    Thanks in advance!!!

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    This would let you access the account names, full names, etc:

    How to list all Windows Users- Andreas Kraus: C#, ASP.NET, Silverlight

    It basically wraps a WMI object -- to access other properties, you can use this reference:

    Win32_UserAccount Class (Windows)

    That one gets most of the info you asked about. Not sure about home directory though. You may need to query the UserProfile class:

    Win32_UserProfile Class (Windows)
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by Cat View Post
    This would let you access the account names, full names, etc:

    How to list all Windows Users- Andreas Kraus: C#, ASP.NET, Silverlight

    It basically wraps a WMI object -- to access other properties, you can use this reference:

    Win32_UserAccount Class (Windows)

    That one gets most of the info you asked about. Not sure about home directory though. You may need to query the UserProfile class:

    Win32_UserProfile Class (Windows)
    Thank you very very much !!! It completely works.

    Now the only problem I got is that I can't seem to find a user's group. I can get all the current users and their names etc, but there's no option to find the group a certain user belongs too. Got a solution for that?

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    There's a GroupUser WMI class but I've never tried to use it:

    Win32_GroupUser Class (Windows)

    I did find this post on CodeProject, which may be more than you need, but it wraps the WMI behavior inside C# classes. Even if you don't need/use the wrappers it should help with the WMI stuff:

    Re: Users in local users and groups [modified] - C# Discussion Boards - CodeProject
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  2. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 02:12 PM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21