Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created August 21, 2012 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dck-jp/3414988 to your computer and use it in GitHub Desktop.
Save dck-jp/3414988 to your computer and use it in GitHub Desktop.
Yet another Task.Exists() @ VBA
' Yet another Task.Exists()
' Task.Exists() Method does not always work well.
' processName : executeFileName eg. "notepad.exe"
Function TaskExists(processName As String)
Dim Locator : Set Locator = CreateObject("WbemScripting.SWbemLocator")
Dim Server : Set Server = Locator.ConnectServer
Dim objSet : Set objSet = Server.ExecQuery("Select * From Win32_Process")
Dim obj
For Each obj In objSet
If obj.Caption = processName Then
TaskExists = True
Exit Function
End If
Next
TaskExists = False
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment