Other Languages - Scheduling tasks using Batch command script.

Asked By RAJESH VEMUNOORI on 24-Aug-11 07:35 AM
Hello everybody,

I need to create a batch file for scheduling some tasks. Can any one suggest me how to do the same with out using Schedule Tasks GUI.

Rajesh Vemunoori.
Jitendra Faye replied to RAJESH VEMUNOORI on 24-Aug-11 07:42 AM
You could run it silently using a Windows Script file instead. The Run Method allows you running a script in invisible mode. Create a .vbs file like this one
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\Scheduled Jobs\mybat.bat" & Chr(34), 0
Set WinScriptHost = Nothing

and schedule it. The second argument in this example sets the window style. 0 means "hide the window."

Complete syntax of the Run method:

 object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])


  • object: WshShell object.
  • strCommand: String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file.
  • intWindowStyle: Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information.
  • bWaitOnReturn: Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).

Hope this will help you.

Reena Jain replied to RAJESH VEMUNOORI on 24-Aug-11 10:01 AM

1. Create a scheduled task which simply executes a batch file, say c:\mybatch.bat. You can disable this scheduled task because you don't really want it to run on a schedule, but rather when you tell it to.

2. Create a new file which contains the path and filename of the batch file you really want to execute, and save this new file as c:\mybatch.bat (such that when the scheduled task is run, it will execute this new batch file).

3. In your web app code, create a new process which will simply run the schedule task, as follows: myprocess.StartInfo = new ProcessStartInfo("cmd.exe", "schtasks /run /TN \"task-name\"");

or check this link