[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,043
    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. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,115
    60
    #4 Muerto, Apr 20, 2012
    Last edited: Aug 22, 2021
    ...
     
  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,515
    7,171
    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...