Skip to main content

Scripts​

With a script you can automate almost anything in Windows. This page is for anyone who runs scripts from VisualCron. It shows which Task to use for each kind of script, and how to run PHP and VBScript scripts.

Use these Tasks:

To run a script that is on a web server, use the HTTP Task to send a GET or POST request to it.

Using PHP for scripting​

PHP is a free scripting language that can, for example, work with databases, read and process files, and send email. You can download it from php.net.

To run a PHP script, add an Execute Task and set:

  • Command: the full path to "php.exe", for example "C:\php\php.exe"
  • Arguments: -q and then the full path to the script, for example -q "C:\Scripts\report.php"

-q suppresses HTTP header output when PHP runs as CGI. With the command-line "php.exe" it has no effect, but it does no harm. The console window is hidden because Run in hidden window is selected, which is the default.

If the script uses relative paths, select Working directory and enter the folder those paths start from. When Working directory is not selected, the script does not run in its own folder, so its relative paths can point to the wrong place.

Execute tab of an Execute Task, with Command set to c:\php\php.exe, Arguments set to -q c:\yourscript.php, Working directory selected with no folder, and Run in hidden window selected

Using VBScript for scripting​

VBScript is a Windows scripting language. Microsoft has deprecated it, so for new scripts consider the PowerShell Task. VisualCron still runs existing VBScript scripts, as long as VBScript is available on the Server computer.

The easiest way is the Execute Script Task. It runs the script with "cscript.exe" in a hidden window. By default, it keeps what the script writes as the Task's output, and the Task fails if the script writes to standard error (see the On error tab). You have two ways to give it the script:

  • Select Script file and enter the full path to the script in File path. Put quotes around a path that contains spaces
  • Select Script text and type the script

Execute script tab of an Execute Script Task, with No Credential selected, the Script file and File path fields, and Script text selected with an empty script editor

To use the Execute Task instead, set Command to "C:\Windows\System32\cscript.exe" and Arguments to "C:\Scripts\dosomething.vbs" //NoLogo.

warning

Use "cscript.exe", not "wscript.exe". The "wscript.exe" host shows the script's messages, such as WScript.Echo, in message boxes instead of writing them as output. The Task output then stays empty, and a message box that nobody closes keeps the Task running until it is stopped, or until its timeout if one is set.

If you enter a ".vbs" or ".js" file in Command of an Execute Task, the Client offers to move it to Arguments and set Command to "wscript.exe". If you accept, change Command to "C:\Windows\System32\cscript.exe" afterwards.

Third-party tools​

You can use VisualCron to start other programs, for example a backup program at a set time. Use the Execute Task. By default it runs the program in a hidden window, under the account of the VisualCron service or the Credential selected in Run Task as. With the default settings, a program that waits for someone to type or click does not get that input. If a program behaves differently than when you start it yourself, see Windows Command Does Not Execute Correctly.

To suggest a tool, see Commands, Scripts, and Third Party Tools.

NirCmd​

NirCmd is a free command-line utility from NirSoft. It performs many small Windows actions without showing a window, for example changing registry values, creating shortcuts or turning off the monitor. Download it from nirsoft.net.