To run external program on local computer using WSH (Window Scripting Host), you can create an object WScript.Shell and invoke its Runmethod, e.g.:
Dim Obj
Set Obj = CreateObject("WScript.Shell")
Obj.Run "notepad.exe"
To run external program on remote computer (e.g. in local area network), you can use the following VBScript Function:
Function startExe(sstrComputer,sstrEXE)
'Starts a process on a machine
'Input: sstrComputer = machine name (use "." for local)
'Input: sstrExe = Exe or command to execute (can pass full command line)
'Output: boolean
'Optional: Declare startExeStatus as a global variable to get status text
startExe = False
Set sobjWMIService = GetObject("winmgmts:\\" & sstrComputer & "\root\cimv2:Win32_Process")
sintReturn = sobjWMIService.Create(sstrEXE, null, null, sintProcessID)
Select Case sintReturn
Case 0 'Successful Completion
startExe = True
startExeStatus = "Successful Completion"
Case 2 'Access Denied
startExe = False
startExeStatus = "Access Denied"
Case 3 'Insufficient Privilege
startExe = False
startExeStatus = "Insufficient Privilege"
Case 8 'Unknown Failure
startExe = False
startExeStatus = "Unknown Failure"
Case 9 'Path not found
startExe = False
startExeStatus = "Path not found"
Case 21 'Invalid Parameter
startExe = False
startExeStatus = "Invalid Parameter"
Case Else
startExe = False
startExeStatus = "Error code " & sintReturn & " not found"
End Select
End Function
To run a local command, use “.” for the first parameter, for example, startExe(“.”, “notepad.exe”).
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: The Ultimate Famicom Game Cartridge - N8 Everdrive - Installed on BBG Famiclone
Next Post: C/C++ Coding Exercise - Unique Paths II - Dynamic Programming with Obstacles - Leetcode Online Judge - DP with Constraints