Please disregard that, some mishap with the refresh button.
I suppose you mean something like 'finger' on unix?
Main Topics
Browse All TopicsI run a program with the scheduler (the AT command at the DOS prompt) that needs to know the username of the currently logged on user. Since the scheduler is a service, all I can get as a username is "SYSTEM".
Would anyone know how to get this info?
I did find some information in the registry under HKEY_LOCAL_MACHINE\system\
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I don't know what finger does in UNIX, sorry.
But I can try to be a bit clearer:
When the computer starts, the scheduler service starts also.
At some point, independently of a user logging in, the service will launch my program.
But since the scheduler is a service, it runs with the user "SYSTEM", and that doesn't suit my needs, for I need to know the user name of the user who's connected at that moment, if any.
Well, it's not a simple as you might expect. The problem is that there can be any number of logged on users, from 0 - N. Which one do you want? Each user has his own desktop.
To determine a logged on user, first figure out which desktop you want to find the current user for. Use EnumWindowStations to find all the window stations. Usually there is only one of interest but there is no guarantee of this.
Then, for each window station call EnumDesktops to find all the desktops in the window station.
Then for the desktop you are interested in finding the user for, use GetUserObjectInformation to get the SID for the user of that desktop.
OK, here is what I do:
The scheduler is started on 2000 computers and runs once per hour to execute a bach file over the network.
Among other things, that batch file should get the value of %username%. Naturally, if I do exactly that, I will get the user "SYSTEM".
So I wanted to write a little program that the batch file would run and that would print the list of the currently logged in users to the screen.
It so happens that there always is a user (called "WINST") logged in, but I can sort the user names later on.
I am not familiar to those functions "EnumWindowStations" and "EnumDesktops". Would I get the actual user names after that?
No, you'll get the SID of the users of the various desktops. (Of course under most circumstances there will be only one but it's foolish to assume that this will always be the case!!) With the SID you can find the user name with LookupAccountSid().
These functions are not as difficult as they appear at first glance. The Enum... functions just enumerate all the possibilities and you just call the Get... or Lookup.. functions on the returned handles until you find what you are looking for. Do you have MSDN? It's all documented in there....
It's actually a lot easier:
- Enumerate all running apps, looking for 'explorer.exe'
- Call 'OpenProcessToken( ..., TOKEN_QUERY,...);'
- Use the resulting token in a call to 'QueryTokenInformation(...
- Use the returned SID to retrieve the user name:
if ( !GetSecurityDescriptorOwne
&psid,
&bDefaulted
)
)
{
dwErr = GetLastError ();
}
// lookup clear text name of the owner
if ( !LookupAccountSid ( NULL,
psid,
acBuffer,
&dwNameSize,
acReferencedDomain,
&dwDomainBufSize,
&eUse
)
)
{
dwErr = GetLastError ();
}
>>Consider the Windows Terminal Services case as one
>>possibility.
Yes, you're correct - but the same problem would arise with desktops IIRC (not too familiar with TS)
Anyway, in both cases there is not a single logged on user...
Another idea that would (should) also work for both cases is enumerating the HKEY_USERS key - the subkeys are the direct textual representations of the logged on users' SIDs.
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity, I will suggest to accept "jhance" comment(s) as an answer since you seemed to prefer his solution.
If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchang
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Business Accounts
Answer for Membership
by: KangaRooPosted on 2001-06-22 at 06:46:51ID: 6218352
If there is a user logged on at all....