Hi,
I need some code to kill a specific process running...
I looked up all this forum's posts about killing processes, But I didn't find what I need! ... I need to kill a process by Its extension name, NOT by Its caption or title...!
Thanx.
Printable View
Hi,
I need some code to kill a specific process running...
I looked up all this forum's posts about killing processes, But I didn't find what I need! ... I need to kill a process by Its extension name, NOT by Its caption or title...!
Thanx.
i maybe can,
but maybe don't want to help you looking at your previous posts on the forum...
unless you have a very good explanation for wanting to write/delete read-only files and to close processes...
I totally Agree and respect your opinion
u see.. I need to make a simple remover tool for Perlovga warm that makes an Autorun for HDs ... etc
And my other request for read-only ... was bcuz I wanted to edit the boot.ini file (For Personal Use).
simply thats all! :)
To kill it you need to find the process ID or window handle. When killing it by filename problems may occur if you have two processes with the same filename.
Heres how to get the filename and process ID of all processes running:
http://vbforums.com/showthread.php?t...hlight=process
and heres how to kill it by the ID:
http://en.allexperts.com/q/Visual-Ba...s-VB-its-1.htm
From those to samples you should be able to create an app that allows you to enter a filename, and have it kill that process.
allright ;)
srry bout that then...
let's see
VB Code:
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Public Declare Function terminateprocess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Const TH32CS_SNAPPROCESS = &H2 Public Const TH32CS_SNAPheaplist = &H1 Public Const TH32CS_SNAPthread = &H4 Public Const TH32CS_SNAPmodule = &H8 Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule Public Const MAX_PATH As Integer = 260 Public 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 Public Sub KillProcessById(p_lngProcessId As Long) On Error Resume Next Dim lnghProcess As Long Dim lngReturn As Long lnghProcess = OpenProcess(1&, -1&, p_lngProcessId) lngReturn = terminateprocess(lnghProcess, 0&) If lngReturn = 0 Then 'RetrieveError End If End Sub Public Sub KillProcess(ProcessName As String) On Error Resume Next Dim LoopI Dim Proc As PROCESSENTRY32 Dim Snap As Long Dim ExeName As String Dim ext As String Snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) Proc.dwSize = Len(Proc) LoopI = ProcessFirst(Snap, Proc) While LoopI <> 0 ExExist = False ExeName = LCase(Proc.szExeFile) ext = Split(ProcessName, ".")(1) ExeName = Split(ExeName, ext)(0) ExeName = ExeName & ext If ExeName = ProcessName Then KillProcessById (Proc.th32ProcessID) DoEvents Exit Sub End If LoopI = ProcessNext(Snap, Proc) Wend CloseHandle Snap End Sub
Thanx the182guy, but Its a lil difficult for me to put all that together :D
Besides, TheBigB's code is piece of cake ;)