I am trying to create a VBScript that creates a batch file and then creates a scheduled task to run a batch file. So far, everything I tried creates a batch file, but does not create a scheduled task, and I have not received any errors. Here is what I still have:
Option Explicit
Dim objFSO, outFile, wShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outFile = objFSO.CreateTextFile("C:\test.bat", True)
outFile.WriteLine "Start www.google.com"
outFile.Close
Set wShell = CreateObject ("Wscript.Shell")
wShell.Run "cmd SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN 'Test Task' /TR 'C:\test.bat' /ST 16:30", 0
I tried ""Test Task""and ""C:\test.bat""got the same results. But when I run the following command on the command line:
SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN "Test Task" /TR "C:\test.bat" /ST 16:30
The task is created successfully.
In another way, I tried to create 2 batch files: one batch file to open a web page and one batch file to create a scheduled task. Then I finished working with the file task.batat the end. Here is what I did for this:
Option Explicit
Dim objFSO, outFile, wShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outFile = objFSO.CreateTextFile("C:\test.bat", True)
outFile.WriteLine "Start www.google.com"
outFile.Close
Set outFile = objFSO.CreateTextFile("C:\task.bat", True)
outFile.WriteLine "SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN ""Test Task"" /TR ""C:\test.bat"" /ST 16:30"
Set wShell = CreateObject ("Wscript.Shell")
wShell.Run "cmd start ""C:\task.bat"""
, cmd .
, wShell.Run, , , .
, , .