6

I have a batch file that creates a scheduled task using schtasks like this:

schtasks /create /tn my_task_name 
                 /tr "...\my_path\my_task.bat"
                 /sc daily
                 /st 10:00:00 
                 /s \\my_computer_name 
                 /u my_username    
                 /p my_password

It works OK except the fact that when my_task.bat is executed - a new command line window is opened (and closed after execution).

I would like to avoid opening this new window (i.e. to run the task in quiet mode, in the background).

I thought to use

start /b ...\my_path\my_task.bat

but I don't know how, because since I have to call start from the batch file I need to precede it with cmd /c, which again causes the new window to open.

How could I solve this problem ?

4 Answers 4

3

I believe you're seeing the box because the account you set to run it as is your own. Try either of these:

1: Run the task as the user NT Authority\System

2: Make a new account and set the task to run with its credentials

4
  • Could you add more details regarding the first option ? I don't really understand what Authority\System is. Thanks a lot ! Oct 3, 2010 at 5:44
  • @Misha: NT Authority\System is sort of an unadvertised system account that is responsible for running basic Windows services. Stuff that goes on all the time in many cases requires credentials and this is the way Windows handles it. Hit ctrl+alt+del, open task manager and tab to processes. You'll see many that are listed as user "System." That is NT Authority\System. When you go to set up the task using NT Authority\System, you'll not have to enter a password. Just leave that blank. Oct 3, 2010 at 21:06
  • I tried to set /u "NT Authority\System" /p "", and got the following error: ERROR: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again... What am I doing wrong ? Oct 4, 2010 at 13:11
  • That sounds like you might have something in your batch file open under your own credentials already--perhaps a network drive. I would need to see your batch file (mytask.bat) to answer knowledgeably. Oct 6, 2010 at 2:06
3

You can do this by specifying /RU option for schtasks. This option

specifies the user account (user context) under which the task runs. For the system account, valid values are "", "NT AUTHORITY\SYSTEM" or "SYSTEM".

And thus, try this

schtasks /create /tn my_task_name 
                  ....
                 /st 10:00:00 
                 /ru "SYSTEM"
                 ....
3
  • So for some values of /RU the command-line window suppressed? Which ones? Is this documented somewhere?
    – martineau
    Nov 15, 2012 at 17:49
  • Nope. I even didn't try to find. I found this workaround to solve my problem in some blog post and utilized it.
    – pmod
    Nov 15, 2012 at 21:24
  • schtasks /create /? you get the help message and ref this docs.microsoft.com/en-us/windows-server/administration/… Sep 20, 2018 at 6:29
1

Perhaps using the AT command and don't include the /interactive switch.

Example:
AT \\my_computer_name 10:00AM /EVERY:M,T,W,Th,F,S,Su "...\my_path\my_task.bat"

If you need specific credentials for my_task.bat to run under, you will pobably have to put RUNAS in the command because I believe the command will run under the security context of the Schedule (Task Scheduler) service which is the "Local System" account. Adding the RUNAS command and switches before you BAT file should fix that.

1

Finally, I used this code to solve the problem:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "...\my_task.bat" & Chr(34), 0
Set WshShell = Nothing

saved it in run_my_task.vbs and scheduled run_my_task.vbs with schtasks as above.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .