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) —
239 wordsLast 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
I want to trigger a script which is there in remote machine using your code and need a log file in local machine like successfully executed or failure in case issues.
when I provide incorrect computer name, its shows errors in screen, instead I want that in log file and its has to proceed for another machine,
how can I call the above function, I have added below lines in bottom of your script and executed.
dim result
dim var1
result=startExe(“.”,”cscript c:\temp\hellow.vbs” )
var1=msgbox(result)
On Error Resume Next?
could you please provide entire script, Get servers from txt file and execute the script which is there in remote machine then write into log file like Successfully executed, “server not reachable”, “Access denied”,
Thank you, very useful.
Glad you like it.