Detect if a certain application is running?

L

Legacy 98055

Guest
Wrong forum? So what. I have had good luck here with questions such as these.

If I have App_A running and want to prevent the user from running another instance of the same app, how might I detect if this App is running? The application contains no windows.

Thanks,
Tom
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about use Mutex of API? When you run the App, create "Test Mutex", and when quit the App, use ReleaseMutex function.

here is a sample...<PRE>Private Declare<FONT color=red>Function</FONT>CreateMutex Lib "kernel32" Alias "CreateMutexA" ( _<FONT color=red>ByRef</FONT> lpMutexAttributes<FONT color=red>As</FONT> Any, _<FONT color=red>ByVal</FONT> bInitialOwner<FONT color=red>As</FONT><FONT color=red> Long</FONT>, _<FONT color=red>ByVal</FONT> lpName<FONT color=red>As</FONT><FONT color=red> String</FONT>)<FONT color=red>As</FONT><FONT color=red> Long</FONT>

Private Declare<FONT color=red>Function</FONT>ReleaseMutex Lib "kernel32" ( _<FONT color=red>ByVal</FONT> hMutex<FONT color=red>As</FONT><FONT color=red> Long</FONT>)<FONT color=red>As</FONT><FONT color=red> Long</FONT>

Private Declare<FONT color=red>Function</FONT>OpenMutex Lib "kernel32" Alias "OpenMutexA" ( _<FONT color=red>ByVal</FONT> dwDesiredAccess<FONT color=red>As</FONT><FONT color=red> Long</FONT>, _<FONT color=red>ByVal</FONT> bInheritHandle<FONT color=red>As</FONT><FONT color=red> Long</FONT>, _<FONT color=red>ByVal</FONT> lpName<FONT color=red>As</FONT><FONT color=red> String</FONT>)<FONT color=red>As</FONT><FONT color=red> Long</FONT>

Private Declare<FONT color=red>Function</FONT>CloseHandle Lib "kernel32" ( _<FONT color=red>ByVal</FONT> hObject<FONT color=red>As</FONT><FONT color=red> Long</FONT>)<FONT color=red>As</FONT><FONT color=red> Long</FONT>



Private<FONT color=red>Const</FONT>ERROR_ALREADY_EXISTS = 183&

Private<FONT color=red>Const</FONT>MUTEX_ALL_ACCESS = &H1F0001

Private lngMutex<FONT color=red>As</FONT><FONT color=red> Long</FONT><FONT color=red>Sub</FONT>Auto_Open()

lngMutex = OpenMutex(MUTEX_ALL_ACCESS, 0, "Test Mutex")<FONT color=red>If</FONT>lngMutex = 0 Then

lngMutex = CreateMutex(<FONT color=red>ByVal</FONT> 0, 0, "Test Mutex")<FONT color=red>Else</FONT><FONT color=red>Call</FONT> CloseHandle(lngMutex)<FONT color=red>Call</FONT> MsgBox("The App is running already")<FONT color=red>End If</FONT><FONT color=red>End Sub</FONT><FONT color=red>Sub</FONT>Auto_Close()<FONT color=red>Call</FONT> ReleaseMutex(lngMutex)<FONT color=red>End Sub</FONT></PRE>

_________________
With Regards,
Colo

You can release your free soft ware on my site. Please email your file to me. Thanks.
This message was edited by Colo on 2002-08-25 23:14
 
Upvote 0
Hi Colo.
Your time was not wasted. I will save your example when using Excel. This was for a VB app and I should have specified that.

If App.PrevInstance = True Then
MsgBox "This program is already running."
End
End If

Thanks,
Tom
 
Upvote 0
On 2002-08-25 21:11, TsTom wrote:
Wrong forum? So what. I have had good luck here with questions such as these.

If I have App_A running and want to prevent the user from running another instance of the same app, how might I detect if this App is running? The application contains no windows.

Thanks,
Tom

Hi Tom
Try this ?? Note your'll need the Applications Class Name.

<pre/>
Function IsAppARunning() As Boolean
// Returns False if NOT running
Dim objApp As Object

Const ERR_APP_NOTRUNNING As Long = 429
On Error Resume Next

Set objApp = GetObject(, "ClassName")

If Err <> ERR_APP_NOTRUNNING Then
MsgBox "You must close AppA if you want to run this program" _
& vbCrLf & "Close AppA and try again", , "Warning"
IsAppARunning = True
Exit Function
Else
IsAppARunning = False
End If

End Function

</pre>
 
Upvote 0
On 2002-08-25 23:15, TsTom wrote:
Hi Colo.
Your time was not wasted. I will save your example when using Excel. This was for a VB app and I should have specified that.

If App.PrevInstance = True Then
MsgBox "This program is already running."
End
End If

Thanks,
Tom
Thanks Tom,
I wanted to say is... When you run Another App from your code, Create Mutex.
But Ivan's way is better...for all I know. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top