Set background application active - Suppress Dialog Form at Startup

Posted on 2007-08-06
Last Modified: 2013-11-05
Hello, I am using VB.NET 2003 and I have 2 windows applications that will be somewhat dependent on each other. The majority of the time users will open the first and then open the second one from the first. However, an user could also open the second application by itself without opening the first one.  Both of them have a login password dialog form at startup for security purposes.

I want the first app to check whether the other one is opened or not.  If it's opened, then I need to make the second application the active window.

However, if the second application is not opened, I need to open it and bypass the login password question diaog form because they've already it entered it once when opening the first app.

On the other hand, if someone chooses to open the second application by itself, the login password dialog form should always appear.

I know how to check whether the second app is running or not.  I only need to know how to 'activate' and bring it to the front so it becomes the active window.

Also, I'm using the following code to start the second application if it is not running in the background
  Private Sub StartMyApp(ByVal AppPath As String)

        ' Declare the Process variable.
        Dim proc As Process
        ' Ensure that the file exists
        If System.IO.File.Exists(AppPath) = False Then
            Exit Sub
        End If
        ' Create the Process component.
        proc = New Process
        ' Set EnableRaisingEvents to True.
        proc.EnableRaisingEvents = True
        ' Add an event handler to trap the Exited event.
        AddHandler proc.Exited, AddressOf OnProcessExit
        ' Build the StartInfo object.
        ' Set the FileName property to the argument that was passed.
        proc.StartInfo.FileName = AppPath
        ' Enable the ErrorDialog.
        proc.StartInfo.ErrorDialog = True
        ' Start the Process

    End Sub

    ' Event Handler for Process.Exited Event
    Private Sub OnProcessExit(ByVal sender As Object, ByVal e As EventArgs)
        ' Avoid late binding and cast the Object to a specific Process component.
        Dim proc As Process = CType(sender, Process)
        ' Write out the Exit information.
        ' Dispose and Clear the object.
        proc = Nothing
    End Sub

However, I don't know how to stop the password login dialog form from showing up if I open it from the first app.

This is the code I'm using to show the login password dialog screen when loading the second app main form:

    Private Sub LoadPasswordForm()

        ' Show the Password screen in dialog form
        Dim dlg As New frmPassword
        'try again flag
        'check the outcome of the dialog result
        Select Case dlg.ShowDialog
            Case DialogResult.OK
                'The password was correct, exit this process
            Exit Sub              
            Case DialogResult.Retry
                'Wrong password, try again
                GoTo tryagain
            Case DialogResult.Cancel
                'User wants to exit the application
        End Select

    End Sub

I would like that when the user wants to open the second app from the first to bypass the login dialog form altogether by setting up a boolean variable (false value as default) in the main form that will either skip the code above if provided (as True) or always run it if not provided (false).

Does anyone have a good solution for this?


Question by:TheUndecider
    LVL 96

    Expert Comment

    by:Bob Learned
    That is a lot of words, so what is your question put simply?


    Author Comment

    Hi Bob, right now, what I need is to be able to open a second .net application from a first one without the second showing a dialog form asking for a password when opening.  

    However, if I try to open that second application by itself, it should ask me for the password by showing a dialog form at startup.

    I hope that's simple enough.  Let me know if you need more info.

    LVL 96

    Accepted Solution

    I would think that you could pass in command line arguments when calling the 2nd application.  If it is started independently, those command line arguments wouldn't be passed.


    Author Comment

    Thanks Bob for your reply.  That is what I actually did.  I opened my second app from the first one passing the password as an argument.  Then, in my second program I have a select case that checks for the string passed.  if it is the actual password it will not load the password dialog form.  Otherwise, (like if opening the second app directly from its folder or a shortcut) it will load the password dialog form.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now