[VB.NET]All Active window will be and close it

Discussion in 'Mixed Languages' started by jcgo16, Apr 20, 2012.

  1. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    #1 jcgo16, Apr 20, 2012
    Last edited: Apr 20, 2012
    I want to close all active window

    If the program detects any active window, it will close it

    opps sorry, my bad, i have to change the title
     
  2. redroad

    redroad MDL Guru

    Dec 2, 2011
    5,326
    6,009
    180
    #2 redroad, Apr 20, 2012
    Last edited: Apr 20, 2012
  3. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    sorry for misunderstanding my topic title and post

    btw im looking for a code in vb.net


    <3
     
  4. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,530
    1,388
    60
    You can work off of this...


    1. Start notepad
    System.Diagnostics.Process.Start("notepad")

    2. Start winword
    System.Diagnostics.Process.Start("WINWORD")

    3. Start excel
    System.Diagnostics.Process.Start("Excel")

    4. Start ie and parameter
    System.Diagnostics.Process.Start("IExplore.exe", "http://www.websitehere.com")

    5. Kill It!!
    ' Kill all notepad process
    Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

    For Each p As Process In pProcess
    p.Kill()
    Next
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    thats the problem, what if you dont know whats the active windows
     
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,112
    120
    #6 Josh Cell, Apr 21, 2012
    Last edited by a moderator: Apr 20, 2017
    It will check if the window is active and close it by logged user: [C#]

    Code:
                foreach (Process MainProc in Process.GetProcesses(Environment.MachineName)) //ForEarch all logged user processes
                {
                    if (MainProc.MainWindowHandle != IntPtr.Zero) //Check if the current process have an window
                    {
                        MainProc.Kill(); //Kill the process if pass on the window check
                       
                    }
                }
    [VB]

    Code:
    For Each MainProc As Process In Process.GetProcesses(Environment.MachineName)
        If (MainProc.MainWindowHandle <> IntPtr.Zero) Then
            MainProc.Kill()
        End If
    Next
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...