schtask Activate task when specific user login

1

I want to create a batch file that creates a scheduled task to run a .cmd file when a specific user logons. So far I've come up with this:

@echo off
schtasks /CREATE /RU %username% /TN "TaskName" /TR "C:\folder\file.cmd" ^
                                        /SC ONLOGON /DELAY 0000:10 /IT /RL highest
PAUSE

which creates the task just fine, but when looking at the trigger properties the option 'Any user' is checked instead of 'Specific user'. I've tried looking to solutions everywhere but everything seemed to point to using /IT with /RU.

Also as a side question, do I need to include /PU in the script? I plan on running the batch file on multiple machines and feel that it will be a security/implementation issue to ask people for their passwords.

Kustomize

Posted 2015-06-15T05:36:26.670

Reputation: 51

Keep in mind, though, that while this is correct, that the task will run when a different user is logged on if the originally specified user is still logged on from a previous session. Where this is not the case with the GUI's "at log on of a specific user" option. – Daniel Goudie – 2017-05-08T18:46:23.903

Answers

0

As mentioned at https://technet.microsoft.com/en-us/library/cc725744(v=ws.11).aspx "the /it parameter to indicate that the task runs only when the (specific user) is logged on"

You should disregard the Task Scheduler GUI where "At log on of any user" is mentioned and actually try rebooting your device. You'll find that the specific command is only run when you log in with the (specific user)'s account.

Agrim

Posted 2015-06-15T05:36:26.670

Reputation: 1

Keep in mind, though, that while this is correct, that the task will run when a different user is logged on if the originally specified user is still logged on from a previous session. Where this is not the case with the GUI's "at log on of a specific user" option. – Daniel Goudie – 2017-05-08T18:46:23.903