Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting a program

Status
Not open for further replies.

MrChopper

Programmer
Aug 11, 2004
20
US
Is it possible for vbscript to detect if a program is running (access.exe for example)? If so, how would I go about doing it? TFTH
 
Something like this ?
Function isRunning(strComputer As String, strName As String) As Boolean
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process",,48)
For Each objItem in colItems
If Trim(objItem.ExecutablePath & "") <> "" Then
If LCase(objItem.Name) = LCase(strName) Then
isRunning = True
Exit Function
End If
End If
Next
isRunning = False
End Function
MsgBox "Access is running ? " & isRrunning(".", "msaccess.exe")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hmmm, I'm getting some errors from that.... is it for VB only?
 
Hello MrChopper,

PHV's script is clear enough for the working steps. Just take out the type setting (As Boolean, As String etc) and it will work.

regards - tsuji
 
also in the last MsgBox, change isRrunning to isRunning (only one R)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top