Can you redirect focus from one process to a child process?

ikantspelwurdz

Well-known member
Joined
Dec 8, 2009
Messages
49
Programming Experience
1-3
I have a simple forms app with two buttons. Button "Runas" spawns a child process with admin privileges. Button "Close" closes the form. Here is the entire code:
VB.NET:
Public Class Form1

    Private Sub B_Runas_Click(sender As System.Object, e As System.EventArgs) Handles B_Runas.Click
        Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
        startInfo.UseShellExecute = True
        startInfo.WorkingDirectory = Environment.CurrentDirectory
        Dim uri As Uri = New Uri(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
        startInfo.FileName = uri.LocalPath
        startInfo.Verb = "runas"
        Try
            Dim p As Process = Process.Start(startInfo)
            p.WaitForExit()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub B_Close_Click(sender As System.Object, e As System.EventArgs) Handles B_Close.Click
        Me.Close()
    End Sub
End Class

There is a usability problem here. Let's say you run this, and click the "Runas" button. Depending on your UAC settings, Windows prompts you to grant this app admin privileges. So you click "yes." Another form opens up, and it looks the same as the first. Now form instance #1 is frozen, and form instance #2 is usable. So far, so good. Now you check your e-mail, putting both windows in the background. But then you return to this app. There are two forms open in the task bar. You click on the first form instance in the task bar, and nothing at all happens. If you click the SECOND form instance, all is well, but it would be better if the user didn't have to remember this.

What I want to happen is that when you click on form instance #1 in this situation, it would redirect your focus to form instance #2. Can this be done? This is how it would work if all of the form instances were part of the same process.
 

Latest posts

Back
Top