Skip to content

Instantly share code, notes, and snippets.

@andreburto
Created February 15, 2018 23:49
Show Gist options
  • Save andreburto/39ffc0322597ac479a036a79fb8819a5 to your computer and use it in GitHub Desktop.
Save andreburto/39ffc0322597ac479a036a79fb8819a5 to your computer and use it in GitHub Desktop.
' Credit where it is due:
' http://computerperformance.co.uk/
' https://msdn.microsoft.com/en-us/library/aa394372(v=vs.85).aspx
' ----------------------------------------------------------------------
Option Explicit
Dim objWMIService, objShell, objProcess
Dim strComputer, colProcess, procName, procPath
procName = "notepad++.exe"
strComputer = "."
Set objWMIService = GetObject("winmgmts:!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcess
If Len(objProcess.ExecutablePath) > 0 And objProcess.Name = procName Then
procPath = objProcess.ExecutablePath
objProcess.Terminate()
End If
Next
Set objShell = CreateObject("WScript.Shell")
objShell.run """"&procPath&"""", 0, false
WScript.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment