• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

Set background application active - Suppress Dialog Form at Startup

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?


  • 2
  • 2
1 Solution
Bob LearnedCommented:
That is a lot of words, so what is your question put simply?

TheUndeciderAuthor Commented:
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.

Bob LearnedCommented:
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.

TheUndeciderAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now