In my daily life as Consultant for VMware I implement a lot of customer specific scripts using the ThinApp scripting engine and I just thought: Why not share these scripts?
The following script can be used if a ThinApp application can or should not be launched if a specific process is already running. In this particular case a virtualized instance of SAP should only be able to launch if no native instance of SAP is running already.
' Run script if an entry point is launched<br>Function OnFirstParentStart
' Initialize variables
Dim objWMIService, objWMIProcess, objShell
Dim strTitle, strMessage, strComputer, strProcess
' Set computer to localhost
strComputer = "."
' Set process to check
strProcess = "saplogon.exe"
' Set error message
strTitle = "VMware ThinApp"
strMessage = "The process " & strProcess & "is already running!" & Vbcrlf & "Please close the process and then try again."
intButton = 48
' Connect to WMI service
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colWMIProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & strProcess & "'")
If colWMIProcess.Count > 0 Then
' Display message box
Msgbox strMessage, intButton, strTitle
' End of OnFirstParentStart Function
To implement this script in your ThinApp project just save the code above as .vbs file in your ThinApp projects folder und customize the variable strProcess. Just enter the process you want to check and you are ready.
You can also customize the error message the user gets by modifying the variable strMessage.