Results 1 to 4 of 4

Thread: End Task Application

  1. #1

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    End Task Application

    You know how you can press Alt + Ctrl + Delete, and a list of programs popup that are running. And then how you can select one and end task it, how can I endtask a program that I already know that is running if it is called Choke??
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  2. #2
    Matthew Gates
    Guest
    This code works for Win9.x. Doesn't work for WinNT though .


    VB Code:
    1. Private Declare Function ProcessFirst Lib "kernel32" _
    2. Alias "Process32First" (ByVal hSnapshot As Long, uProcess _
    3. As PROCESSENTRY32) As Long
    4.  
    5. Private Declare Function ProcessNext Lib "kernel32" _
    6. Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As _
    7. PROCESSENTRY32) As Long
    8.  
    9. Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _
    10. Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _
    11. lProcessID As Long) As Long
    12.  
    13. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
    14. As Long) As Long
    15.  
    16. Private Declare Function OpenProcess Lib "kernel32" (ByVal _
    17. dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    18. ByVal dwProcessId As Long) As Long
    19.  
    20. Private Declare Function TerminateProcess Lib "kernel32" _
    21. (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    22.  
    23.  
    24.  
    25. Type PROCESSENTRY32
    26.     dwSize As Long
    27.     cntUsage As Long
    28.     th32ProcessID As Long
    29.     th32DefaultHeapID As Long
    30.     th32ModuleID As Long
    31.     cntThreads As Long
    32.     th32ParentProcessID As Long
    33.     pcPriClassBase As Long
    34.     dwFlags As Long
    35.     szexeFile As String * MAX_PATH
    36.     End Type
    37.  
    38.  
    39. Private Const MAX_PATH = 260
    40.  
    41.  
    42. Private Function KillApp(myName As String) As Boolean
    43.     Const PROCESS_ALL_ACCESS = 0
    44.     Dim uProcess As PROCESSENTRY32
    45.     Dim rProcessFound As Long
    46.     Dim hSnapshot As Long
    47.     Dim szExename As String
    48.     Dim exitCode As Long
    49.     Dim myProcess As Long
    50.     Dim AppKill As Boolean
    51.     Dim appCount As Integer
    52.     Dim i As Integer
    53.     On Local Error GoTo Finish
    54.     appCount = 0
    55.    
    56.     Const TH32CS_SNAPPROCESS As Long = 2&
    57.    
    58.     uProcess.dwSize = Len(uProcess)
    59.     hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    60.     rProcessFound = ProcessFirst(hSnapshot, uProcess)
    61.    
    62.     Do While rProcessFound
    63.         i = InStr(1, uProcess.szexeFile, Chr(0))
    64.         szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    65.         If Right$(szExename, Len(myName)) = LCase$(myName) Then
    66.             KillApp = True
    67.             appCount = appCount + 1
    68.             myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    69.             AppKill = TerminateProcess(myProcess, exitCode)
    70.             Call CloseHandle(myProcess)
    71.         End If
    72.         rProcessFound = ProcessNext(hSnapshot, uProcess)
    73.     Loop
    74.  
    75.     Call CloseHandle(hSnapshot)
    76. Finish:
    77. End Function
    78.  
    79.  
    80. [b][u]Usage[/u][/b]
    81.  
    82. Call KillApp("C:\MyDir\Choke.exe")

  3. #3

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Not working

    Code:
    If Right$(szExename, Len(myName)) = LCase$(myName) Then
    This line won't evaluate to true... ever

    the file is "C:\choke.exe"
    The Actaul process is called "choke"

    Please Help
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  4. #4

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    It's ok, I got it

    I got it, it's ok. Thanx
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

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