[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...
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
Re: Close running applications in Winxp using vb code???
Here is the code
VB Code:
Option Explicit
'on win2k you need the following:
Private Const PROCESS_TERMINATE = &H1
'On nt 9X the following could be enough:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
'in any case, let us use both...
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 Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Function KillApp(myName As String) As Boolean
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 iFound As Integer
On Error GoTo ErrHandler
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapShot = CreateToolHelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapShot, uProcess)
Do While rProcessFound
iFound = InStr(1, uProcess.szExeFile, Chr(0)) - 1
If iFound > 0 Then
szExename = LCase$(Left$(uProcess.szExeFile, iFound))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
myProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_TERMINATE, False, uProcess.th32ProcessID)
KillApp = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
'if you have only one, exit here:
'Exit Function
'if you think you may have more than one,
'let this go on
End If
rProcessFound = ProcessNext(hSnapShot, uProcess)
End If
Loop
Call CloseHandle(hSnapShot)
Exit Function
ErrHandler:
MsgBox Err.Description
End Function
This will work on 9x, NT, win 2000, win xp
Re: Close running applications in Winxp using vb code???
thank you 4 all the replies guys...
thanks 4 the code man....
really appreciate it