Show an Already Open Window with a Listbox (VB)












0















Basically, I'm making a manager that will show the window when you either click a button, or the listbox item.



This can be useful, because in I.T. workplaces, there are programs open with several different windows or instances of that one program running, and switching between the tasks can be easier by seeing the specific instance and clicking it to show it, than to scroll through the taskbar trying to find that ONE document you are looking for.



Two questions I have are:




  1. How do I show the window you selected with a button after selecting the instance in the listbox


  2. How do I make it so that it only closes the tab/instance of the program instead of the program?



The kill script I'm using is this



Private Sub btnKill_Click(sender As Object, e As EventArgs) Handles btnKill.Click
Try
Dim whole As String = Search.SelectedItem.ToString
Dim pid = whole.Substring(whole.LastIndexOf(" # "))
pid = pid.Replace(" # ", "")
Dim p As Process = Process.GetProcessById(pid)
Try
p.Kill()
Catch ex As Exception
' MessageBox.Show(ex.Message)
End Try
Catch ex As Exception
' MessageBox.Show(ex.Message)
End Try
Search.Items.Clear()
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle = String.Empty = False Then
Search.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
End If
Next
'For every process running
For Each P As Process In Process.GetProcesses
'Get a list of ALL of the open windows associated with the process
Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
For Each kvp As KeyValuePair(Of IntPtr, String) In windows
If kvp.Value.ToLower = "start" = False Then
lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
Search.Items.Clear()
End If
Next
Next
Try
Dim whole As String = lstMain.SelectedItem.ToString
Dim pid = whole.Substring(whole.LastIndexOf(" # "))
pid = pid.Replace(" # ", "")
Dim p As Process = Process.GetProcessById(pid)
Try
p.Kill()
Catch ex As Exception
' MessageBox.Show(ex.Message)
End Try
Catch ex As Exception
' MessageBox.Show(ex.Message)
End Try
lstMain.Items.Clear()
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle = String.Empty = False Then
lstMain.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
End If
Next
'For every process running
For Each P As Process In Process.GetProcesses
'Get a list of ALL of the open windows associated with the process
Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
For Each kvp As KeyValuePair(Of IntPtr, String) In windows
If kvp.Value.ToLower = "start" = False Then
lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
End If
Next
Next
End Sub


Even if i have, let's say, 3 different word files open, if I kill one, it kills them all. I think it has to do with:



Dim pid = whole.Substring(whole.LastIndexOf(" # "))
pid = pid.Replace(" # ", "")
Dim p As Process = Process.GetProcessById(pid)


Help would be very much appreciated!



THANKS!



-Filip



EDIT: How could I use the "BringtoFront" command with it?










share|improve this question





























    0















    Basically, I'm making a manager that will show the window when you either click a button, or the listbox item.



    This can be useful, because in I.T. workplaces, there are programs open with several different windows or instances of that one program running, and switching between the tasks can be easier by seeing the specific instance and clicking it to show it, than to scroll through the taskbar trying to find that ONE document you are looking for.



    Two questions I have are:




    1. How do I show the window you selected with a button after selecting the instance in the listbox


    2. How do I make it so that it only closes the tab/instance of the program instead of the program?



    The kill script I'm using is this



    Private Sub btnKill_Click(sender As Object, e As EventArgs) Handles btnKill.Click
    Try
    Dim whole As String = Search.SelectedItem.ToString
    Dim pid = whole.Substring(whole.LastIndexOf(" # "))
    pid = pid.Replace(" # ", "")
    Dim p As Process = Process.GetProcessById(pid)
    Try
    p.Kill()
    Catch ex As Exception
    ' MessageBox.Show(ex.Message)
    End Try
    Catch ex As Exception
    ' MessageBox.Show(ex.Message)
    End Try
    Search.Items.Clear()
    For Each p As Process In Process.GetProcesses
    If p.MainWindowTitle = String.Empty = False Then
    Search.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
    End If
    Next
    'For every process running
    For Each P As Process In Process.GetProcesses
    'Get a list of ALL of the open windows associated with the process
    Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
    For Each kvp As KeyValuePair(Of IntPtr, String) In windows
    If kvp.Value.ToLower = "start" = False Then
    lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
    Search.Items.Clear()
    End If
    Next
    Next
    Try
    Dim whole As String = lstMain.SelectedItem.ToString
    Dim pid = whole.Substring(whole.LastIndexOf(" # "))
    pid = pid.Replace(" # ", "")
    Dim p As Process = Process.GetProcessById(pid)
    Try
    p.Kill()
    Catch ex As Exception
    ' MessageBox.Show(ex.Message)
    End Try
    Catch ex As Exception
    ' MessageBox.Show(ex.Message)
    End Try
    lstMain.Items.Clear()
    For Each p As Process In Process.GetProcesses
    If p.MainWindowTitle = String.Empty = False Then
    lstMain.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
    End If
    Next
    'For every process running
    For Each P As Process In Process.GetProcesses
    'Get a list of ALL of the open windows associated with the process
    Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
    For Each kvp As KeyValuePair(Of IntPtr, String) In windows
    If kvp.Value.ToLower = "start" = False Then
    lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
    End If
    Next
    Next
    End Sub


    Even if i have, let's say, 3 different word files open, if I kill one, it kills them all. I think it has to do with:



    Dim pid = whole.Substring(whole.LastIndexOf(" # "))
    pid = pid.Replace(" # ", "")
    Dim p As Process = Process.GetProcessById(pid)


    Help would be very much appreciated!



    THANKS!



    -Filip



    EDIT: How could I use the "BringtoFront" command with it?










    share|improve this question



























      0












      0








      0


      1






      Basically, I'm making a manager that will show the window when you either click a button, or the listbox item.



      This can be useful, because in I.T. workplaces, there are programs open with several different windows or instances of that one program running, and switching between the tasks can be easier by seeing the specific instance and clicking it to show it, than to scroll through the taskbar trying to find that ONE document you are looking for.



      Two questions I have are:




      1. How do I show the window you selected with a button after selecting the instance in the listbox


      2. How do I make it so that it only closes the tab/instance of the program instead of the program?



      The kill script I'm using is this



      Private Sub btnKill_Click(sender As Object, e As EventArgs) Handles btnKill.Click
      Try
      Dim whole As String = Search.SelectedItem.ToString
      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)
      Try
      p.Kill()
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Search.Items.Clear()
      For Each p As Process In Process.GetProcesses
      If p.MainWindowTitle = String.Empty = False Then
      Search.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
      End If
      Next
      'For every process running
      For Each P As Process In Process.GetProcesses
      'Get a list of ALL of the open windows associated with the process
      Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
      For Each kvp As KeyValuePair(Of IntPtr, String) In windows
      If kvp.Value.ToLower = "start" = False Then
      lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
      Search.Items.Clear()
      End If
      Next
      Next
      Try
      Dim whole As String = lstMain.SelectedItem.ToString
      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)
      Try
      p.Kill()
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      lstMain.Items.Clear()
      For Each p As Process In Process.GetProcesses
      If p.MainWindowTitle = String.Empty = False Then
      lstMain.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
      End If
      Next
      'For every process running
      For Each P As Process In Process.GetProcesses
      'Get a list of ALL of the open windows associated with the process
      Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
      For Each kvp As KeyValuePair(Of IntPtr, String) In windows
      If kvp.Value.ToLower = "start" = False Then
      lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
      End If
      Next
      Next
      End Sub


      Even if i have, let's say, 3 different word files open, if I kill one, it kills them all. I think it has to do with:



      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)


      Help would be very much appreciated!



      THANKS!



      -Filip



      EDIT: How could I use the "BringtoFront" command with it?










      share|improve this question
















      Basically, I'm making a manager that will show the window when you either click a button, or the listbox item.



      This can be useful, because in I.T. workplaces, there are programs open with several different windows or instances of that one program running, and switching between the tasks can be easier by seeing the specific instance and clicking it to show it, than to scroll through the taskbar trying to find that ONE document you are looking for.



      Two questions I have are:




      1. How do I show the window you selected with a button after selecting the instance in the listbox


      2. How do I make it so that it only closes the tab/instance of the program instead of the program?



      The kill script I'm using is this



      Private Sub btnKill_Click(sender As Object, e As EventArgs) Handles btnKill.Click
      Try
      Dim whole As String = Search.SelectedItem.ToString
      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)
      Try
      p.Kill()
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Search.Items.Clear()
      For Each p As Process In Process.GetProcesses
      If p.MainWindowTitle = String.Empty = False Then
      Search.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
      End If
      Next
      'For every process running
      For Each P As Process In Process.GetProcesses
      'Get a list of ALL of the open windows associated with the process
      Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
      For Each kvp As KeyValuePair(Of IntPtr, String) In windows
      If kvp.Value.ToLower = "start" = False Then
      lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
      Search.Items.Clear()
      End If
      Next
      Next
      Try
      Dim whole As String = lstMain.SelectedItem.ToString
      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)
      Try
      p.Kill()
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      Catch ex As Exception
      ' MessageBox.Show(ex.Message)
      End Try
      lstMain.Items.Clear()
      For Each p As Process In Process.GetProcesses
      If p.MainWindowTitle = String.Empty = False Then
      lstMain.Items.Add(p.ProcessName & " # " & p.MainWindowTitle & " # " & p.Id)
      End If
      Next
      'For every process running
      For Each P As Process In Process.GetProcesses
      'Get a list of ALL of the open windows associated with the process
      Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
      For Each kvp As KeyValuePair(Of IntPtr, String) In windows
      If kvp.Value.ToLower = "start" = False Then
      lstMain.Items.Add(P.ProcessName & " # " & kvp.Value & " # " & P.Id)
      End If
      Next
      Next
      End Sub


      Even if i have, let's say, 3 different word files open, if I kill one, it kills them all. I think it has to do with:



      Dim pid = whole.Substring(whole.LastIndexOf(" # "))
      pid = pid.Replace(" # ", "")
      Dim p As Process = Process.GetProcessById(pid)


      Help would be very much appreciated!



      THANKS!



      -Filip



      EDIT: How could I use the "BringtoFront" command with it?







      listbox window task show






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 '18 at 20:59







      Filip Budd

















      asked Nov 15 '18 at 18:17









      Filip BuddFilip Budd

      14




      14
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325615%2fshow-an-already-open-window-with-a-listbox-vb%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325615%2fshow-an-already-open-window-with-a-listbox-vb%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma