How to detect if your exe is allready running through a VB script (WSH)

  • Thread starter Thread starter Tobias Eriksson
  • Start date Start date
T

Tobias Eriksson

Hi
I just came across a script that I just had to share, there may be
other ways of doing this, but this is at least one way. I've copied
this script almost right as it is from the following web site:
http://www.rgagnon.com/wshdetails/wsh-0020.html
so he(they) should have all the credits.


To determine if your application is running when you are about to
install an upgrade for example you can use the script below. Well,
this is just a stub, you need to make changes in order to fit your
needs, like setting an MSI variable or poping up a dialog like I did
below.

***************************
Set WshShell = WScript.CreateObject("WScript.Shell")

Set locator = CreateObject("WbemScripting.SWbemLocator")
Set service = locator.ConnectServer()
Set props = service.ExecQuery("select name, description from
Win32_Process where name = 'program.exe'")
num = props.Count

If num > 0 Then
'Program is running
MsgBox "AFP is running!"
Else
'Program is not running
MsGBox "AFP is NOT running!"
End If

Set WSHShell = Nothing
**************************

Regards
Tobias
 
Back
Top