Windows 7 Scheduled task command line

2019-02-10 16:06发布

This command should create a task that every minute runs the calculator windows application.

schtasks /Create /tn "mytask" /sc MINUTE /mo 1  /ru "myuser" /rp "mypassword" /tr "C:\Windows\System32\calc.exe"

It runs OK, the tasks gets added. The task looks right. The tasks shows as started in the schedular but the calculator does not get fired up. The exe exists, I can run it separately.

Anyone know why I don't see the calculator?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-10 16:16

Probably because the task isn't running interactively. Add the '/it' option:

/IT
A value that enables the task to run interactively only if the /RU user is currently logged on at the time the task runs. The task runs only if the user is logged on.

Without the /it option, tasks run in session 0, which doesn't allow interaction with the user. For more information, do a web search for "Session 0 isolation".

查看更多
仙女界的扛把子
3楼-- · 2019-02-10 16:35

How to Create, Modify and Delete Scheduled Tasks from the Command Line Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.

While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:

Manipulate tasks in batch scripts. Control and create tasks on networked machines without having to login to them. Mass create/sync task across multiple machines. Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.

Eg: Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday: SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00

Modify ‘My Task’ to run at 2 PM: SchTasks /Change /TN “My Task” /ST 14:00

Create ‘My Task’ to run C:RunMe.bat on the first of every month: SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM: SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

Delete the task named ‘My Task’: SchTasks /Delete /TN “My Task”

查看更多
登录 后发表回答