# Solved: listing configured users of a computer XP and Vista



## scrfix (May 3, 2009)

I have read through all of the commands I can find on these webites.

Is there no way to display all of the users on a stand alone computer?

I see ways to changes users passwords, I see ways to change the NT Security permissions of that user however is there no way to tell me what users are on the computer.

I have a way devised to tell me this already with a For loop. I am mainly curious if I can find out if I can get a list of users.

My main goal is to clean up the junk temp files and temporary internet files on users other than the main active user.

Such as if I utilize %temp%, this only does the active users temp files however if Susan, Dave and Richard P. Blemmings are also usernames on that computer, I would like to clean up their junk files as well without having to sign into their username.

I figure, I have to have a list of the usernames first, correct? So this brings me back to my original question. Is there an easier, more effecient method of detecting usernames on a computer other than the for loop I have?


----------



## IMiteBable2help (Nov 6, 2001)

So what's the issue? doesn't both XP and Vista boot to a login screen showing the user accounts? (if not, that can be changed)

You can see a list of all accounts in XP by going to control panel < computer management. Then, in the left window pane, under Local Users and Groups<users.

Note that there are several accounts in there with descriptions that are built-in to XP like Guest, ASPNET, help assistant, and support. Ignore those and what's left are created user accounts.

Alternatively, you might want to try this first: Right-click the My Computer icon on your desktop < System Properties, or get into System Properties another way, then click Advanced (tab) then User Profile settings. That will show the accounts, and even show how much space each account is using on the disk.

I don't know about Vista. Had it a few weeks and I hated it. Driver issues, incompatible apps, etc. Haven't used it since.


----------



## scrfix (May 3, 2009)

okay, apparently I wasn't clear enough.

I thought the command line reference would have given it away and the explanation about utilizing %temp%, a command line reference as well as cleaning up the temp files for other users, the FOR Loop mentioned or even the fact that this post is listed in DOS, PDA or Other but apparently I will still not clear enough... 

Let me be a little more clear, this question is for scripting batch files. I am fully aware of how to get a list of users in the GUI many different ways.

I need to know if there is a command line reference that will return a list of currently configured users on a stand alone system. I saw one that can do a work group, domain from active directory and others but none that can return a list of users currently active on the computer. I say currently active because if a user does a dirty install (XP) where they do not format the computer they merely delete the windows directory then you are left with a list in documents and settings of the inactive users as well.

I currently have a script that I can modify that will allow me to clean up all of the junk files for all of the folder names in documents and settings however it would be much more efficient if I knew the active users. The script I have will do both active and inactive.

Hopefully that explains it a little better.

Thanks for your reply and explanation however. Strangely enough, in a round-a-bout way you have pointed me into a new direction. If I utilize the registry to attempt to find these or even if I can utilize the control userpasswords2 somehow to return a list of active users on the computer then that may work so thanks. I will try to go that route.


----------



## TheOutcaste (Aug 8, 2007)

*Net User* - Gets UserName for all local accounts.

Any accounts that have not been signed into won't have a profile folder, so you'd need to do an If Exists for each one.
Note that the UserName is not always the same as the UserProfile. The UserProfile is set when the account is created, The UserName can be changed at any time.
Inactive or Domain accounts won't be listed.

* wmic useraccount get Domain,Name*
Same as above, but if you are connected to the Domain, it will list both Local and _all_ Domain accounts, even if they have never signed into the particular PC.

To find the UserProfile path for _only_ current accounts, the Registry is the way to go.
Query this key:

```
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
```
Find the ones starting with *S-1-5-21*
Then query those for the *ProfileImagePath* value
*S-1-5-18* is the SystemProfile
*S-1-5-19* is the LocalService account
*S-1-5-20* is the NetworkService account

Domain accounts that have logged into this system will also be listed here. If you need to separate those out, you'd need to use *PsGetSID* (part of *PsTools*) from Sysinternals to get the SID of the PC, then you can compare to the keys names found under *ProfileList* to exclude Domain accounts if desired.

Jerry


----------



## Squashman (Apr 4, 2003)

Lots of third party utilities that can enumerate accounts as well. Even remotely.


----------



## scrfix (May 3, 2009)

Jerry,

Thanks for the advice. The "net user" was exactly what I was looking for however very good point about them changing their usernames and them being different from the profile names.

The registry entry will work perfectly. With that, I can grab a list of users and then delete the temp files from those users as well.

That will be a project for this or the next weekend.

Thanks,


----------



## Squashman (Apr 4, 2003)

I guess I don't understand what you are doing. I thought Jerry helped you with a batch file that cleared out the TEMP files already?


----------



## scrfix (May 3, 2009)

Squashman,

The original post explains that. I have one that cleans out the temp files for the active user however this requires me to sign in to each and every user on the computer in order to run that batch file.

I have devised a plan to clean the temp and T.I.F.'s for every user on the computer.

The first step is to figure out what active users are on the computer. That is what the original question was. Now that I know that, I can create (or in my case at this time, attempt to create) a FOR statement which will extract all of the active users on the computer and then with IF statements remove the proper directories with the junk files based upon the operating system.


----------



## Squashman (Apr 4, 2003)

_Posted via Mobile Device_
I could have sworn we covered this already in one of your previous batch files. I am pretty sure you don't have to enumerate accounts to accomplish this task.


----------



## scrfix (May 3, 2009)

I will search our past conversations. I am pretty sure it was just for that active user, deleting the %temp% directory and the temporary internet files but when deleting %temp% directory the compiled bat file would crash.


----------



## TheOutcaste (Aug 8, 2007)

We had a routine to copy the user profiles in this thread (around post 40-50). That same method could be used to delete the temp files, just have to exclude the current user so it won't delete the batch file, and use the method that checks for the compiled batch file for the current user.

That routine would also backup any "inactive" user profiles, which _might_ not be wanted. There might be files to be recovered from them though.

I don't see a downside to deleting the temp files for any "inactive" accounts though. The profiles won't be usable so any temp files will just be wasting space.


----------



## scrfix (May 3, 2009)

Hi Jerry,

That is also semi-referenced in the first post and referenced again in post 3. That is the one I was talking about however that does not return to me the active users. It returns to me the inactive and active users.

Cleaning the temp and temporary internet files for the inactive users is not really efficient since it serves no purpose.

If someone (XP computer) performs a dirty install of the operating system then you will end up with their old usernames on the computer in the documents and settings directory. If I utilize the script, it will look at those every time. Just not as efficient as grabbing the currently active user profiles on the computer.


----------



## TheOutcaste (Aug 8, 2007)

I do understand what you are saying. I just think it does serve a purpose to include inactive users, to free any space used by temp files in the inactive accounts. Since they are inactive, no new files will be created. It will take longer to run the first time, but after that I don't think the time to delete files from an empty folder would be significant, unless they have a _lot_ of inactive users.
It could also be made an option, so you can include inactive users with a command line switch.

Of course, if part of the cleanup will be to recover files from these inactive accounts, then delete them, if you do that first, it won't matter because they won't exist.

As for efficiency, I did a few time trials.
To determine the OS, and list all users, active and inactive on Win2k, XP, and Vista takes 12 lines of code, using 1 For loop. Let's call this the *List All* method.
Excluded All Users, Default, LocalService, NetworkService, and Public on both XP and Vista. Setting the exclusions for each OS didn't make a measurable difference.
To determine the OS, and read the Registry takes 14 lines, and two For loops. Let's call this the *List Active* method.

Tests performed on XP and Vista VMs in VPC 2007.
On XP:


 Tested with 3 active users and no inactive.
 Then added 4 inactive users.
 Am deleting the Temp folder then recreating it.
(Having to special case the current user when using a compiled batch would need to be done regardless of the method).
On Vista

Tested with 4 users including the Guest account
My Guest account doesn't have a Temp folder, but it is listed in the Registry.
Then added 4 inactive users
Ran each test 7 times, discarded the fastest and slowest times, then averaged the remaining 5.


```
With no inactive users
Method        XP      Vista
List all    0.376     0.224
List Active 1.068     0.976

With  inactive Users
List All    0.426     0.230
List Active 1.054     0.928
```
So reading the Registry is slower. The more users, the slower it will be, as a separate Reg Query needs to be done for each account.

It is a better way to go though, as it will find the active accounts even if the Profile Folder has been relocated.

But then there's the issue of dual boot systems, with XP on one partition and Vista on another. Or even worse, someone who has XP and Vista installed on the _same_ partition...

Jerry


----------



## scrfix (May 3, 2009)

Wow!!

There is no room for discussion on that. Jerry, you have an extreme knack for being able to take every possible option out of a particular scenario so that there is no room for discussion. Here are the facts.. period... 

Well, it appears I will take your advise and not utilize the registry. I thought that would be a more efficient way to go due to it being only active users however most computers are not going to an extreme amount of inactive users. The most I have ever seen was around 15 inactive users because their last computer guy only knew how to format and reinstall their computer. He did not actually know how to repair the issues is what is presumed. Every time they brought it in for service, it would come back with what they thought was no data on it. They were ecstatic when I "found" their data for them.

Ok. I am convinced, I will modify and utilize the original script I have for deleting those temp and temporary internet files.

Thanks again

Jerry,

Completely off the subject. From the command line, is there a way to test to see if an account has a password associated with it?

I don't care what the password is. I just want to know whether they have a password on the account. Is that possible? I have been searching everywhere I can find but have not found the answer as to whether that is even possible. The current user account is all that I care about at this time.


----------

