Skip to main content

 

Kill a Windows Process

3 months ago
OfflineStanley Johnson
Stanley Johnson
Description:  Kill a Running Windows Process.  In the case below the script is configured to kill Winword.exe but a simple change in the configuration area will allow you to kill other processes.  Note:  if multiple instances of the process are running they will all be killed.
Language: VB Script/JScript
Code:
 

'Script Description.
'Kills a Windows process.
'-----------------------------------------

'Declarations
option explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
Dim ScriptName

'Configuration area.  Set the following configuration fields for your environment.
'----------------------------------------------------------
ScriptName = context.GetProperty("ActionTypeName")  'Get's the Action Name
strComputer = context.GetProperty("Address")         'Gets the IP address from WUG
strProcessKill = "'Winword.exe'"

Context.LogMessage( ScriptName & " - Starting")
Context.LogMessage( ScriptName & " - Address = " & strComputer)
Context.LogMessage( ScriptName & " - Process = " & strProcessKill)

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
   objProcess.Terminate()
   Context.LogMessage( ScriptName & " - Killed Process")
Next
Context.LogMessage( ScriptName & " - Done")

-----
You liked this too2 people like this discussion.
 
Concluded

0 Conclusions:

0 Replies

Would you like to comment?

You must be a member. Sign In if you are already a member.

  • 306 views
  • $obj.VersionIndex versions
  • 0 replies
  • 0 followers
     
Post Date:
January 17, 2012
Posted By:
Stanley Johnson

About this forum

  • 21,991 views
  • 19 topics
  • 4 followers
     

Viewed 306 times