Get current user from system account 2
Posted on 2001-07-05
This question is related to a previous one: How can I get the current interactive logon user from a service running under the system account?
The answer provided by Epsilon was really good, although the circumstances have now changed.
- The Current user is NOT running explorer as shell. Instead, it's running a custom application, which may change for different users.
- The applications to be run as shell, have different class names and window names. The only common thing is the user that's logged on interactively (always same user).
- The Current user may or may NOT be running a shell (the custom application running as a shell may have crashed, hung or exit prematurely)
The service is running under the sytem account and have interact with desktop rights.
I tried looking for winsta0\default, but although it works fine on some computers running 2000 SP2, it fails on those running Win2K Sp1 (always return SYSTEM as user)
Because there's no specific application to look for, I've found no way fo getting ahold a windows handle to identify the owner.
The thing is that the service is kind of a watchdog service that is monitoring the application running as a shell for specific user. The computer autologons this user all the time.
If the application stop responding of exits prematurely, the service must logoff that user (and only that user!)inmediatelly, to cleanup the user environment and reload the application (by logging on the user again via autologon)