WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Run an Application on a Remote Computer

Keywords:  Run Launch Application Program Process Remote Computer Machine RPC Remote Procedure Call     

Question:

Is there any way to run an application remotely on a WIndows 95/98/ME machine? If so, does anyone have a sample script? Thanks.

Answer:

You might be able to use WMI to do it...
The WMI operating system core components are generally supported on most Windows platforms. For more information about WMI see: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582(v=vs.85).aspx
The Create WMI class method creates a new process. A fully-qualified path needs to be specified in cases where the program to be launched is not in the search path of Winmgmt.exe. If the newly created process attempts to interact with objects on the target system without appropriate access privileges, it is terminated without notification to this method.

For security reasons the Win32_Process.Create method cannot be used to start an interactive process.


NOTES:

Sample code:

;***************************************************************************
;** RunRemote(ComputerName,Application,WorkingDir,UserName,Password)
;** Runs an application on a remote computer.
;** 
;** Parameters:
;** ComputerName: Computer name without \\, and "" for local.
;** Application: Program to run. Can include full path or UNC. Can also include Parameters.
;** WorkingDir: Working Directory for program or "" for default.
;** UserName: User name to run program as
;** In format DOMAIN\User or just User for local, "" for current user running script.
;** MUST be "" for local computer or the function will fail.
;** Password: Password for user or "" if username is "".
;** 
;** Returns:
;** Result: the result of the create call.
;** Value Meaning 
;** 0 Successful completion 
;** 2 Access denied 
;** 3 Insufficient privilege 
;** 8 Unknown failure 
;** 9 Path not found 
;** 21 Invalid parameter 
;**
;** !!!!!!! NOTES !!!!!!!!!
;** If the newly created process attempts to interact with objects on the target system without 
;** appropriate access privileges, it is terminated without notification to this method.
;**
;** Note  The Win32_Process.Create method cannot be used to start an interactive process for security reasons.
;**
;***************************************************************************
#DefineFunction RunRemote(ComputerName,Application,WorkingDirectory,User,Password)
Locator = ObjectOpen("WbemScripting.SWbemLocator")
Service = Locator.ConnectServer(ComputerName,"root/cimv2",User,Password)
Security = Service.Security_
Security.ImpersonationLevel = 3
Class = Service.Get("Win32_Process")
If WorkingDirectory == "" then
Result = Class.Create(Application)  ;no working directory specified
Else
Result = Class.Create(Application,WorkingDirectory) ;pass the specified working directory
EndIf
ObjectClose(Class)
ObjectClose(Security)
ObjectClose(Service)
ObjectClose(Locator)
Return Result
#EndFunction

ComputerName = "SCOOBY" ;remote machine name (specify "" for local machine)
Application = "Notepad.exe"
WorkDir = ""
User = ""
Password = ""
rslt = RunRemote(ComputerName,Application,WorkDir,User,Password)
Switch rslt
	Case 0
		Message("RunRemote","Successful completion ")
		break
	Case 2
		Message("RunRemote","Access denied")
		break
	Case 3
		Message("RunRemote","Insufficient privilege")
		break
	Case 8
		Message("RunRemote","Unknown failure")
		break
	Case 9
		Message("RunRemote","Path not found")
		break
	Case 21
		Message("RunRemote","Invalid parameter")
		break
	Case rslt
		Message("RunRemote","Unknown error")
		break

EndSwitch

exit

Article ID:   W15362
File Created: 2012:10:03:11:15:30
Last Updated: 2012:10:03:11:15:30