PDA

View Full Version : How can I collect all of the system user names?


searcher123
10-24-2008, 06:32 PM
On a multiuser system, how can I collect all of the system's user names when my Setup is executed under Administrator permission? :huh

Best Regards

jassing
10-24-2008, 08:28 PM
On a multiuser system, how can I collect all of the system's user names when my Setup is executed under Administrator permission? :huh

Best Regards

You would have to query the system -- or an easier, less "exact" way would be to look at the documents & settings folder & scan all the 1st level subdirs.

searcher123
10-25-2008, 03:06 AM
You would have to query the system -- or an easier, less "exact" way would be to look at the documents & settings folder & scan all the 1st level subdirs.

Thanks to answer Jassing,
Document & Settings scanning is not practicability, but how should I query the system?

Regards

pww
10-25-2008, 10:00 AM
actually scanning folder names in Document & Settings is a good way for getting a list of *real* users. You should ignore stuff like
All Users
Default User
NetworkService
LocalService

and the rest of the folder names should correspond to the user profiles existing on the system. This way you'll not get the names of automatically created users such as ASPNET, IUSR_<MachineName>, IWAM__<MachineName> etc.

Another way for getting a full list of user names is to redirect the output of the
net user
command to a text file, like to File.Run a command like
net user > C:\users.txt

and then parse C:\users.txt to obtain a list of users

-----
note that there could be localization issues if you choose to scan the "Documents and Settings" folder.
I have no idea whether this folder is named "Documents and Settings" on non-English systems, nor if the names of the folders inside like "All Users" , "NetworkService" etc. are the same on non-English systems - this is something you should check.

jassing
10-25-2008, 10:56 AM
Thanks to answer Jassing,
Document & Settings scanning is not practicability, but how should I query the system?

Regards

Why is it not practical?
There are api's to query the user database; I dont' know them off the top of my head... If the system is part of a network; you can talk to the AD (windows based) or NOS....
In the absence of details, If it were me; I'd scan the directory.

jassing
10-25-2008, 11:09 AM
note that there could be localization issues if you choose to scan the "Documents and Settings" folder.
I have no idea whether this folder is named "Documents and Settings" on non-English systems, nor if the names of the folders inside like "All Users" , "NetworkService" etc. are the same on non-English systems - this is something you should check.



I would use something like:
%CommonDocumentsFolder% .. "..\.." to get to the "root" of documents & settings; then scan it. That way; if it's different (and would work on vista/xp) you'd be good.

Of course, this method assumes you're not supporting win9x. But if you are; net user wont' help you either...

searcher123
10-25-2008, 03:47 PM
(...)Another way for getting a full list of user names is to redirect the output of the net user (...)

Thanks for your suggestion. If I don't find any better solution way, I will use Net User indubitable. :yes

Best Regards

searcher123
10-25-2008, 03:53 PM
Why is it not practical?(...)

For many reasons ;)

The follow is a very simple example:

1. Create a new limited user called "TEST_User"
2. Restart your system and log-in as TEST_User
3. Restart your system again and log-in as a user with Admin permission.
4. Delete the TEST_User account fully (i.e. when the system asked "Do you want to delete TEST_User files", click on Delete Files key).
5. restart your system again and point to Document & Settings dir. What do you see? Yes, TEST_User dir is there :eek:, but where is the user? you killed him/her :o

Best Regards

ShadowUK
10-26-2008, 01:32 AM
For many reasons ;)

The follow is a very simple example:

1. Create a new limited user called "TEST_User"
2. Restart your system and log-in as TEST_User
3. Restart your system again and log-in as a user with Admin permission.
4. Delete the TEST_User account fully (i.e. when the system asked "Do you want to delete TEST_User files", click on Delete Files key).
5. restart your system again and point to Document & Settings dir. What do you see? Yes, TEST_User dir is there :eek:, but where is the user? you killed him/her :o

Best Regards

Or if you rename it, The folder is still called the old name.