Results 1 to 4 of 4

Thread: [RESOLVED] Close running applications in Winxp using vb code???

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    29

    Resolved [RESOLVED] Close running applications in Winxp using vb code???

    Guys,

    I need to write a simple application in vb6 that would close other currently running applications in windows xp
    Very similar to ending process in task manager.

    please help guys and if u have the code, please do provide it, replies would be highy appreciated.

    reply soon...

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Close running applications in Winxp using vb code???

    Have you tried searching the forum? The FAQ? I'm pretty sure someone's mentioned the same process recently

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Close running applications in Winxp using vb code???

    Here is the code
    VB Code:
    1. Option Explicit
    2. 'on win2k you need the following:
    3. Private Const PROCESS_TERMINATE = &H1
    4. 'On nt 9X the following could be enough:
    5. Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    6. 'in any case, let us use both...
    7. Private Const MAX_PATH As Integer = 260
    8.  
    9. Private Type PROCESSENTRY32
    10.   dwSize As Long
    11.   cntUsage As Long
    12.   th32ProcessID As Long
    13.   th32DefaultHeapID As Long
    14.   th32moduleID As Long
    15.   cntThreads As Long
    16.   th32ParentProcessID As Long
    17.   pcPriClassBase As Long
    18.   dwFlags As Long
    19.   szExeFile As String * MAX_PATH
    20. End Type
    21.  
    22. Private Declare Function CreateToolHelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    23. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    24. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    25. Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
    26. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    27. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    28.  
    29. Public Function KillApp(myName As String) As Boolean
    30.     Dim uProcess As PROCESSENTRY32
    31.     Dim rProcessFound As Long
    32.     Dim hSnapShot As Long
    33.     Dim szExename As String
    34.     Dim exitCode As Long
    35.     Dim myProcess As Long
    36.     Dim iFound As Integer
    37.    
    38.     On Error GoTo ErrHandler
    39.    
    40.     Const TH32CS_SNAPPROCESS As Long = 2&
    41.    
    42.     uProcess.dwSize = Len(uProcess)
    43.     hSnapShot = CreateToolHelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    44.     rProcessFound = ProcessFirst(hSnapShot, uProcess)
    45.    
    46.     Do While rProcessFound
    47.        iFound = InStr(1, uProcess.szExeFile, Chr(0)) - 1
    48.        If iFound > 0 Then
    49.            szExename = LCase$(Left$(uProcess.szExeFile, iFound))
    50.        
    51.            If Right$(szExename, Len(myName)) = LCase$(myName) Then
    52.                
    53.                myProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_TERMINATE, False, uProcess.th32ProcessID)
    54.                KillApp = TerminateProcess(myProcess, exitCode)
    55.                Call CloseHandle(myProcess)
    56.                
    57.                
    58.                'if you have only one, exit here:
    59.                'Exit Function
    60.                'if you think you may have more than one,
    61.                'let this go on
    62.            End If
    63.            rProcessFound = ProcessNext(hSnapShot, uProcess)
    64.        End If
    65.     Loop
    66.     Call CloseHandle(hSnapShot)
    67.     Exit Function
    68. ErrHandler:
    69.     MsgBox Err.Description
    70. End Function
    This will work on 9x, NT, win 2000, win xp
    CS

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    29

    Re: Close running applications in Winxp using vb code???

    thank you 4 all the replies guys...
    thanks 4 the code man....
    really appreciate it

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