Sunday 18 March 2018

batch - How to execute a scheduled task with "schtasks" without opening a new command line window?


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 ?



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...