On a Windows Vista Business machine, I have Windows Task Scheduler task set to run everytime any user logs in. The task runs as a certain elevated admin user because the script is being executed from a fileserver that requires that user's authentication for access and the script in question will be performing operations that need full control of the machine it's being executed on. The script runs great, accesses the network resources, and does administrative tasks fantastically, however, the %username% and other environment variables are for elevated user and not the user who has actually logged in.
Is there a way to run the task elevated with the current logged in user's environment variables? Or is there some way I can find out what account the elevated prompt has been executed from within (if I can find this out, I can get the environment variables for that user)?
To help make my question more clear, here's a scenario and a line from my script. Suppose the regular non-admin user named Bob logs in. Task Scheduler fires the script as an elevated user iAmAdmin. The script executes a command:
eventcreate /t information /id 118 /l SYSTEM /so "My Script" /d "%username% logged in on %date% at %time%"
The %username% in the description shows up as iAmAdmin instead of Bob. Is there a way to get the %username% (or any other environment variables) for the account from which the elevated prompt was started (i.e. Bob shows up for %username% instead of iAmAdmin since Bob's account is the one that is logged in)?
(Note: the use of eventcreate was just an example. The script does a lot more than that, so the issue here isn't with eventcreate, but some of the operations require the actual logged in users environment variables.)