Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Windows Server 2008 task scheduler to run a task when a user logs on, but I would like some way of the task being able to access the name of the user who is logging on. I don't know if there is an environment variable I can access in the task or I can add something in as a parameter when the task runs?

share|improve this question


You might want to attach the trigger of your task to a certain event so you can reference the event's data. I can't exactly tell you what event you would want to attach the trigger to (e.g. is it only remote logins you're interested in, etc.), but I think this might very well be what you're looking for.

Hope it helps!

Original answer:

You might want to have a look at this handy list, which should give you an idea. In the most simple of cases %USERNAME% might just be what you need (e.g. in a batch file you might run).

share|improve this answer
%USERNAME% returns the username which the task is running under, which is always the same user - I want to know the username that has logged on – wizzardmr42 Apr 12 '13 at 8:36
Gotcha. Changed my answer to what I hope is somewhat more appropriate :). – Michael Biech Apr 12 '13 at 9:28

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.