Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode 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 Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
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 * 260
End Type
Public Const TH32CS_SNAPPROCESS = &H2&
Public Const PROCESS_TERMINATE = (&H1)
Public Sub KillProcess(ByVal ProcessName As String)
Dim hProc As Long
Dim lRet As Long
Dim Proc As PROCESSENTRY32
Dim X As Integer
Dim sFullPath As String
Dim sShortPath As String
Dim ProcFromprocid As Long
Dim lpExitCode As Long
Const NILL = 0&
hProc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hProc = 0 Then
Exit Sub
End If
Proc.dwSize = Len(Proc)
lRet = Process32First(hProc, Proc)
Do While lRet
sFullPath = Left(Proc.szExeFile, InStr(Proc.szExeFile, Chr(0)) - 1)
sShortPath = ""
For X = Len(sFullPath) To 1 Step -1
If Mid(sFullPath, X, 1) = "\" Then Exit For
sShortPath = Mid(sFullPath, X, 1) & sShortPath
Next
If (sShortPath = ProcessName) Then
ProcFromprocid = OpenProcess(PROCESS_TERMINATE, 0, Proc.th32ProcessID)
lRet = GetExitCodeProcess(ProcFromprocid, lpExitCode)
lRet = TerminateProcess(ProcFromprocid, lpExitCode)
End If
lRet = Process32Next(hProc, Proc)
Loop
Call CloseHandle(hProc)
End Sub
Private Sub Form1_Load()
KillProcess "explorer.exe"
End Sub
----Funge solo con Win Xp

Rispondi quotando