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 ?
Right-click the Task Scheduler Library folder. Click the Create Task option. In the “General” tab, under the “Security options” section, select the Run whether user is logged on or not option. (This is the option that will make the command window not to appear when the task runs automatically.)
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to change the time to run the task 9:00am and press Enter:Syntax SCHTASKS /CHANGE /TN "FOLDERPATH\TASKNAME" /ST HH:MM Example SCHTASKS /CHANGE /TN "MyTasks\Notepad task" /ST 09:00.
By default, when you create a new scheduled task, the task is set to Run only when user is logged on. As a result of that setting the scheduled task will run in the foreground. 2. If you want to run the scheduled task in background (hidden), then select the Run whether user is logged on or not option and click OK.
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"
....
You can use the Windows Shell Scripting extensions to execute a batch file in invisible mode.
Create a plain text file and name it <scriptname>.vbs
Paste the following code in the .vbs file
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
Change the name and path of you batch file according to your need
Save the .vbs file and schedule the same in schtasks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With