Datamation Logo

System Administration: Script to Execute/Kill Remote Applications

September 23, 2003
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More .

Author:Darron Nesbitt
Platform: Windows NT, Windows 2000
Type: VBScript

DESCRIPTION: These two scripts utilize WMI to connect to and run or kill an application on a remote PC. The scripts will run on Windows 2000 or Windows NT.

Execute Remote App script:

This script when executed prompts for the following:

Remote computer’s name

Path to application that will be executed on the remote computer

Path to directory Application resides in

Onces succesfully started a process id will be returned along with the process owner.


Kill Remote App script:

This script when executed prompts for the following:

Remote computer’s name

Process ID of the application to kill

Download the script.
Scroll down to view the script.


SCRIPT:


'************************************************************************
'*		This script is for executing an application on a remote
'*		computer running Win2K or WinNT w/WMI installed.
'*
'*		Author: Darron Nesbitt
'*		Date: 	7/10/2001
'*
'************************************************************************

Dim strComputerName ' The Computer Name to be queried via WMI
Dim strWinMgt		' The WMI management String

On Error Resume Next

'get computer's name or ip address
strComputerName = ucase(InputBox("Enter the remote computers name or IP","Computer Name/IP"))
AppPath = ucase(InputBox("Enter path to application:" & VBCRLF & VBCRLF & "Example:C:WINNTSYSTEM32Calc.exe","Application Path"))
WorkingDirectory = ucase(InputBox("Enter path to application directory" & VBCRLF & VBCRLF &  "Example: C:WINNTSYSTEM32","Application Working Directory"))
strWinMgt = "winmgmts://" & strComputerName & ""

'
' Get Computer/User Info
'
 Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem")
 for each CompSys in CompSysSet
 strDescription = CompSys.Description
 strModel= CompSys.Model
 strName= CompSys.Name
			strManufacturer	= CompSys.Manufacturer
			strUserName		= CompSys.UserName
 next

 CompInfo = "Computer Information" & VBCrLf & VBCrLf
 CompInfo = CompInfo & "Computer Name: " & strName & VBTab & "User: " & strUserName & VBCrLf

'connect to processes
Set Process = GetObject(strWinMgt).Get("Win32_Process")

'start app
RetVal = Process.Create (AppPath,WorkingDirectory,null,PID)

'if 0 not returned error
if RetVal  0 then
	MsgBox "Error: " & Err.Description & ":" & Err.Number
else

	'build ProcessInfo string
	Set Processes = GetObject(strWinMgt).ExecQuery("select * from Win32_Process where ProcessID = " & PID)
	for each Process in Processes
		RetVal = Process.GetOwner(strUser,strDomain)
		ProcessInfo = "Name: " & Process.Caption & VBTAB & "ProcessID: " & PID & VBCRLF
		ProcessInfo = ProcessInfo & "Process Owner: " & ucase(strDomain) & "" & ucase(strUser) & VBCRLF
	next

	'display info about computer and process
	RetVal = MsgBox (CompInfo & VBCRLF & VBCRLF & "Application started." & VBCRLF & VBCRLF & _
			 		 	ProcessInfo,VBOKOnly,strComputerName & " - Start Application")
end if

msgbox "Done!!"




'************************************************************************
'*		This script is for Killing an application on a remote
'*		computer running Win2K or WinNT w/WMI installed. To use you need
'*		the process id of the application.
'*
'*		Author: Darron Nesbitt
'*		Date: 	7/10/2001
'*
'************************************************************************

Dim strComputerName ' The Computer Name to be queried via WMI
Dim strWinMgt		' The WMI management String

On Error Resume Next

'get computer's name or ip address
strComputerName = ucase(InputBox("Enter the remote computers name or IP","Computer Name/IP"))
PID = InputBox("Enter the applications Process ID","Process ID to Kill")
strWinMgt = "winmgmts://" & strComputerName & ""

'
' Get Computer/User Info
'
 Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem")
 for each CompSys in CompSysSet
 strDescription = CompSys.Description
 strModel= CompSys.Model
 strName= CompSys.Name
			strManufacturer	= CompSys.Manufacturer
			strUserName		= CompSys.UserName
 next

 CompInfo = "Computer Information" & VBCrLf & VBCrLf
 CompInfo = CompInfo & "Computer Name: " & strName & VBTab & "User: " & strUserName & VBCrLf

'build ProcessInfo string
Set Processes = GetObject(strWinMgt).ExecQuery("select * from Win32_Process where ProcessID = " & PID)
for each Process in Processes
	RetVal = Process.GetOwner(strUser,strDomain)
	ProcessInfo = "Name: " & Process.Caption & VBTAB & "ProcessID: " & PID & VBCRLF
	ProcessInfo = ProcessInfo & "Process Owner: " & ucase(strDomain) & "" & ucase(strUser) & VBCRLF

	'display info about computer and process
	RetVal = MsgBox (CompInfo & VBCRLF & VBCRLF & "Application to Kill:" & VBCRLF & VBCRLF & _
		 		 	ProcessInfo & VBCRLF & VBCRLF & "Do you want to kill this process?",VBYesNo,strComputerName & " - Kill Application")
	if RetVal = 6 then
		RetVal = Process.Terminate(0)
	end if
next

'if 0 not returned error
if RetVal  0 then
	MsgBox "Error: " & Err.Description & ":" & Err.Number
end if


msgbox "Done!!"


Disclaimer: We hope that the information in these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided “as -is”, without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. I shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

  SEE ALL
APPLICATIONS ARTICLES
 

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Advertisers

Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.

Advertise with Us

Our Brands


Privacy Policy Terms & Conditions About Contact Advertise California - Do Not Sell My Information

Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.