Checking for instance of program

This one may not be possible and probably has nothing to do with

VB. I created an executable with VB6 that I don't want to be able to

be openned more than once. In other words, If it is running, I don't want

to be able to open another instance of it.

Probably not possible huh??

Thanks

Albert


Comments

  • : This one may not be possible and probably has nothing to do with

    : VB. I created an executable with VB6 that I don't want to be able to

    : be openned more than once. In other words, If it is running, I don't want

    : to be able to open another instance of it.

    : Probably not possible huh??

    : Thanks

    : Albert


    Place code like this in Form_Load

    or in Main, or where ever first

    code is exercised for your app.


    'Solution #1 No info to User

    'No more than 1 instance allowed

    If App.PrevInstance Then End



    'Solution #2 Info to User

    Dim Mg as String

    Dim NL as String 'new line

    Dim DNL as String 'double new line

    Dim a as String

    NL = Chr(13) & Chr(10)

    DNL = NL & NL

    'No more than 1 instance allowed

    If App.PrevInstance Then

    a = "Copy of App is active"

    mg = "An instance of YOUREXENAME.EXE "

    mg = mg & "is already active on the "

    mg = mg & "desktop. It might be minimized."

    mg = mg & DNL$ & "Only 1 instance is allowed. "

    mg = mg & "Will be exiting without activating "

    mg = mg & "a copy after you click OK."

    rem albert, change next code line for to VB6

    rem format if needed, its VB3 format.

    MsgBox mg, 64, a

    End

    End If





  • : : This one may not be possible and probably has nothing to do with

    : : VB. I created an executable with VB6 that I don't want to be able to

    : : be openned more than once. In other words, If it is running, I don't want

    : : to be able to open another instance of it.

    : : Probably not possible huh??

    : : Thanks

    : : Albert


    : Place code like this in Form_Load

    : or in Main, or where ever first

    : code is exercised for your app.


    : 'Solution #1 No info to User

    : 'No more than 1 instance allowed

    : If App.PrevInstance Then End




    : 'Solution #2 Info to User

    : Dim Mg as String

    : Dim NL as String 'new line

    : Dim DNL as String 'double new line

    : Dim a as String

    : NL = Chr(13) & Chr(10)

    : DNL = NL & NL

    : 'No more than 1 instance allowed

    : If App.PrevInstance Then

    : a = "Copy of App is active"

    : mg = "An instance of YOUREXENAME.EXE "

    : mg = mg & "is already active on the "

    : mg = mg & "desktop. It might be minimized."

    : mg = mg & DNL$ & "Only 1 instance is allowed. "

    : mg = mg & "Will be exiting without activating "

    : mg = mg & "a copy after you click OK."

    : rem albert, change next code line for to VB6

    : rem format if needed, its VB3 format.

    : MsgBox mg, 64, a

    : End

    : End If


    Thank you

    They both work good and it's a lot simpler then I

    expected.

    Thanks again!

    Albert


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories