Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Detect if a certain application is running?

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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...

    Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" ( _

    ByRef lpMutexAttributes As Any, _

    ByVal bInitialOwner As Long, _

    ByVal lpName As String) As Long

    Private Declare Function ReleaseMutex Lib "kernel32" ( _

    ByVal hMutex As Long) As Long

    Private Declare Function OpenMutex Lib "kernel32" Alias "OpenMutexA" ( _

    ByVal dwDesiredAccess As Long, _

    ByVal bInheritHandle As Long, _

    ByVal lpName As String) As Long

    Private Declare Function CloseHandle Lib "kernel32" ( _

    ByVal hObject As Long) As Long



    Private Const ERROR_ALREADY_EXISTS = 183&

    Private Const MUTEX_ALL_ACCESS = &H1F0001

    Private lngMutex As Long



    Sub Auto_Open()

    lngMutex = OpenMutex(MUTEX_ALL_ACCESS, 0, "Test Mutex")

    If lngMutex = 0 Then

    lngMutex = CreateMutex(ByVal 0, 0, "Test Mutex")

    Else

    Call CloseHandle(lngMutex)

    Call MsgBox("The App is running already")

    End If

    End Sub



    Sub Auto_Close()

    Call ReleaseMutex(lngMutex)

    End Sub


    _________________
    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 ]

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.


    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


    Kind Regards,
    Ivan F Moala From the City of Sails

  5. #5
    MrExcel MVP
    Colo's Avatar
    Join Date
    Mar 2002
    Location
    Kobe, Japan
    Posts
    1,456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.
    Hope this helps + pen pineapple apple pen!

    Masaru Kaji aka Colo - cellmasters.net

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com