Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.)

share|improve this question
    
Is the entire scheduled task configured to run under "Bob" or "iAmAdmin"? –  grawity May 11 '12 at 14:13
    
iAmAdmin is the user account that launches the task. The trigger is when any user logs in. –  Trav May 11 '12 at 14:20
    
In that case, "Or is there some way I can find out what account the elevated prompt has been executed from within" can be answered as no, because it wasn't executed from within another account -- it's actually running "on the side", started by Task Scheduler under "iAmAdmin". –  grawity May 11 '12 at 14:23
    
(Also, regarding the specific example of eventcreate -- the same kind of logging is already performed by the Security log in Windows, if logon auditing is enabled.) –  grawity May 11 '12 at 14:25
    
Well, my reasons for using eventcreate is that I want to be able to check to see when the script runs. The custom ID, Source, et al makes it easy for me to track stuff that happens in the script. The login message was just an example :) –  Trav May 11 '12 at 14:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.