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 supported on Windows NT 4.0 with Service Pack 4 or later, including Windows 2000, and on Windows 95 OSR2 and Windows 98.Where can you get WMI?
For Win95, 98, and NT 4.0, if WMI is not already installed, you can download the Windows Management Instrumentation (WMI) CORE 1.5 from Microsoft at:
Download MS WMI Stuff
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:
- 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.
- An alternative would be to have a Winbatch script running continuously on the remote machine and have it monitor for *something*, then launch the necessary app for you...
- When you do not provide a username and password it will run as YOU on the remote computers. i.e., the program on the remote computer will have what ever access rights the person running the main WMI script has.
- If you are a Domain Admin, and you run notepad on a remote computer, the person on that computer could most likely edit any file that you could (possibly anywhere on the domain)!
- On the remote machine, since the application cannot be run interactively, you will not see the application running on the desktop, but you can verify that it is running by going into Task Manager and see the process there.
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