How-to: Run a VBScript file

To run a VB script called myscript.vbs from the command line:

C:\> cscript //nologo myscript.vbs

To run a VBScript from within another VBScript:

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cscript c:\batch\demo.vbs"

Run a CMD batch file

To run a CMD batch file from VBScript:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\batch\test.cmd"

Run a PowerShell script

To run a PowerShell script from VBScript:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "powershell -file ""c:\batch\demo.ps1"""

Related VBScript commands

CSCRIPT - Run a VBScript / Windows Scripting Host (WSH) script.
Hybrid batch/VBScript
Run a script from PowerShell
Run a script from the CMD shell

“Those that set in motion the forces of evil cannot always control them afterwards” ~ Charles W. Chesnutt


 
Copyright © 1999-2024 SS64.com
Some rights reserved