Created
August 21, 2012 12:14
-
-
Save dck-jp/3414988 to your computer and use it in GitHub Desktop.
Yet another Task.Exists() @ VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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