Results 1 to 11 of 11

Thread: Closing 'hidden' programs!

  1. #1

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Exclamation

    How could I get a list of running programs INCLUDING the ones not shown in the 'Close Program Dialog' ie: stealth/hidden applications

    API?

    Thx...
    IWS

  2. #2
    Guest
    Try this:


    Code:
    Option Explicit
    
    Private Const TH32CS_SNAPPROCESS As Long = 2&
    Private Const MAX_PATH As Integer = 260
    
    Private Type PROCESSENTRY32
      dwSize As Long
      cntUsage As Long
      th32ProcessID As Long
      th32DefaultHeapID As Long
      th32ModuleID As Long
      cntThreads As Long
      th32ParentProcessID As Long
      pcPriClassBase As Long
      dwFlags As Long
      szExeFile As String * MAX_PATH
    End Type
    
    Private Declare Function CreateToolhelpSnapshot _
    Lib "Kernel32" Alias "CreateToolhelp32Snapshot" _
    (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    
    Private Declare Function ProcessFirst Lib "Kernel32" _
    Alias "Process32First" (ByVal hSnapShot As Long, _
    uProcess As PROCESSENTRY32) As Long
    
    Private Declare Function ProcessNext Lib "Kernel32" _
    Alias "Process32Next" (ByVal hSnapShot As Long, _
    uProcess As PROCESSENTRY32) As Long
    
    Private Declare Sub CloseHandle Lib "Kernel32" _
    (ByVal hPass As Long)
    
    
    Private Sub Command1_Click()
    
        Dim hSnapShot As Long
        Dim uProcess As PROCESSENTRY32
        Dim r As Long
    
        hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    
        If hSnapShot = 0 Then
            Exit Sub
        End If
    
        uProcess.dwSize = Len(uProcess)
    
        r = ProcessFirst(hSnapShot, uProcess)
    
        Do While r
            List1.AddItem uProcess.szExeFile
            r = ProcessNext(hSnapShot, uProcess)
        Loop
    
        Call CloseHandle(hSnapShot)
    
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Talking Alright!

    Geez! Thanx Matt!! Thats awesome! (it also made me realize how much crap I have running simultaneously...)

    k, you think you'r so smart (even though you are :P) how could I close one of those applications, using a method that involves the code you gave me earlier (and not the code to remove a window with a certain 'caption')... Thanx again!
    IWS

  4. #4
    Guest
    Here's another method.

    Add to a Module.
    Code:
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    
    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim Length As Long
        Dim sName As String
        Dim Temp As String
        Static iCount As Integer
        
        iCount = iCount + 1
        Length = GetWindowTextLength(hwnd) + 1
        
        If Length > 1 Then
          sName = Space(Length)
          GetWindowText hwnd, sName, Length
          Debug.Print Left(sName, Length - 1)
        End If
        
        EnumWindowsProc = 1
    End Function
    Usage:
    Code:
    EnumWindows AddressOf EnumWindowsProc, 0

  5. #5
    Guest
    To close programs.
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_QUIT = &H12
    
    Private Sub Command1_Click()
        PostMessage hwnd_of_window, WM_QUIT, 0, 0
    End Sub

  6. #6
    Guest
    Or you could use this code (doesn't work for WinNT though):


    Code:
    Private Declare Function ProcessFirst _
    Lib "kernel32" Alias "Process32First" (ByVal hSnapshot _
    As Long, uProcess As PROCESSENTRY32) As Long
    
    Private Declare Function ProcessNext Lib "kernel32" _
    Alias "Process32Next" (ByVal hSnapshot As Long, _
    uProcess As PROCESSENTRY32) As Long
    
    Private Declare Function CreateToolhelpSnapshot _
    Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal _
    lFlags As Long, lProcessID As Long) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long
    
    Private Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, ByVal bInheritHandle _
    As Long, ByVal dwProcessId As Long) As Long
    
    Private Declare Function TerminateProcess _
    Lib "kernel32" (ByVal hProcess As Long, ByVal _
    uExitCode As Long) As Long
    
    
    Private Type PROCESSENTRY32
        dwSize As Long
        cntUsage As Long
        th32ProcessID As Long
        th32DefaultHeapID As Long
        th32ModuleID As Long
        cntThreads As Long
        th32ParentProcessID As Long
        pcPriClassBase As Long
        dwFlags As Long
        szexeFile As String * MAX_PATH
        End Type
    
    
    Private Const MAX_PATH = 260
    
    
    Private Function KillApp(myName As String) As Boolean
        Const PROCESS_ALL_ACCESS = 0
        Dim uProcess As PROCESSENTRY32
        Dim rProcessFound As Long
        Dim hSnapshot As Long
        Dim szExename As String
        Dim exitCode As Long
        Dim myProcess As Long
        Dim AppKill As Boolean
        Dim appCount As Integer
        Dim i As Integer
        On Local Error GoTo Finish
        appCount = 0
        
        Const TH32CS_SNAPPROCESS As Long = 2&
        
        uProcess.dwSize = Len(uProcess)
        hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
        rProcessFound = ProcessFirst(hSnapshot, uProcess)
        
        Do While rProcessFound
            i = InStr(1, uProcess.szexeFile, Chr(0))
            szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
            If Right$(szExename, Len(myName)) = LCase$(myName) Then
                KillApp = True
                appCount = appCount + 1
                myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
                AppKill = TerminateProcess(myProcess, exitCode)
                Call CloseHandle(myProcess)
            End If
            rProcessFound = ProcessNext(hSnapshot, uProcess)
        Loop
    
        Call CloseHandle(hSnapshot)
    Finish:
    End Function

  7. #7

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Talking

    Thanx for your help, you guys are simply phenomenal!



    A simple question though... Why is it that Microsoft changed the way they coded different versions of windows? For example WinNT and Win98'... What did they change???
    IWS

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    They are coded to operate the best(?) way in the situations and environments they were designed for.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372
    Ok whatever bout windows... (best?) thx...


    About the code you gave me Matt, concerning the Function in the code...
    Code:
    Private Function KillApp(myName As String) As Boolean
    Concerning the 'myName' variable... Is that the name of the application, the pathname of the executable, or the caption in the window?
    IWS

  10. #10

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Question

    MATT???
    IWS

  11. #11
    Matthew Gates
    Guest
    Usage

    Call KillApp("C:\Program.exe")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width