I am running into a problem where a perl script called by the Schedule service in Windows XP is not determining the real locally logged in username. Instead of returning the current username that is logged in, it returns "SYSTEM" which is the account used by Schedule service.
Below are few ways that I tried to identify what username is locally logged into computer console:
1. Environment Variable
$USERID = $ENV{'USERNAME');
Returns no value when the perl script is called by the
scheduler running as SYSTEM.
2. Win32 Function calls
$USERID = Win32::AdminMisc::GetLogonName(); (OR)
$USERID = Win32::LoginName();
Both GetLogonName() and LoginName() return "SYSTEM",
which is the owner of process running the perl script
but not the actual logged in user. By the way, if I
execute the perl script directly and not through the
Scheduler service, it returns the real user name in
all three case show above.
3. Win32::NetAdmin::LoggedOnUsers()
This function is almost perfect, but it has two flaws.
a) It returns accounts that have logged off from
console.
PJaques (Logged off)
MJaques (Logged off)
Administrator (Current Local logged on User)
IWAM_MYCOMPUTER (Used by web server)
b) If a user logs out from computer, LoggedOnUsers()
doesn't indicate that nobody is logged locally
into the computer console.
It seems like there should be an easy way to determine what single user is logged in locally to the computer's console. I just haven't been able to figure out how. Any help would be appreciated. Please provide example. Thanks.
-- Patrick
Below are few ways that I tried to identify what username is locally logged into computer console:
1. Environment Variable
$USERID = $ENV{'USERNAME');
Returns no value when the perl script is called by the
scheduler running as SYSTEM.
2. Win32 Function calls
$USERID = Win32::AdminMisc::GetLogonName(); (OR)
$USERID = Win32::LoginName();
Both GetLogonName() and LoginName() return "SYSTEM",
which is the owner of process running the perl script
but not the actual logged in user. By the way, if I
execute the perl script directly and not through the
Scheduler service, it returns the real user name in
all three case show above.
3. Win32::NetAdmin::LoggedOnUsers()
This function is almost perfect, but it has two flaws.
a) It returns accounts that have logged off from
console.
PJaques (Logged off)
MJaques (Logged off)
Administrator (Current Local logged on User)
IWAM_MYCOMPUTER (Used by web server)
b) If a user logs out from computer, LoggedOnUsers()
doesn't indicate that nobody is logged locally
into the computer console.
It seems like there should be an easy way to determine what single user is logged in locally to the computer's console. I just haven't been able to figure out how. Any help would be appreciated. Please provide example. Thanks.
-- Patrick