Skip to content

Instantly share code, notes, and snippets.

@codeartery
Last active August 21, 2024 06:13
Show Gist options
  • Save codeartery/2459ba6e235b72eba346e192fcf4847f to your computer and use it in GitHub Desktop.
Save codeartery/2459ba6e235b72eba346e192fcf4847f to your computer and use it in GitHub Desktop.
Check if a process is running in VBScript.
Function IsProcessRunning( processNameExe )
IsProcessRunning = GetObject("WinMgmts:\\.\root\cimv2") _
.ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE '" & processNameExe & "'") _
.Count > 0
End Function
Function IsProcessRunning( processNameExe )
IsProcessRunning = GetObject("WinMgmts:\\.\root\cimv2") _
.ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE '" & processNameExe & "'") _
.Count > 0
End Function
'Usage
If IsProcessRunning("notepad.exe") Then
Msgbox "notepad process is running"
Else
Msgbox "notepad process is not running"
End If
' Using wildcards
MsgBox IsProcessRunning("%note%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment