والله تعبت وأني أدور كود لانهاء البرامج بالبروسسر وحصلت علي عدة أكواد لم أعرف عملها بالضبت وهادي الأكواد:
Private Declare Sub ExitProcess Lib "kernel32" ( _ ByVal uExitCode As Long) Private Sub Command1_Click() Dim x as Integer x = 1602 'CLng(Format$(Now + intCmd, "yymmdd")) Set Form1 = Nothing ExitProcess x End Sub
د
هادا بمجرد تشغيله ينهي البروسسر للفيجول أريد أن ينهي برنامج أخر مثل الياهو مع العلم أن
PID = 2676
Handle = 2,018
Destination ("C:\Program Files\Yahoo!\Messenger\YahooMessenger.exe")
وهادا كود أخر:
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 CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _
lProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
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 TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
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 Function KillApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
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 AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
KillApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
Usage
Call KillApp("C:\program.exe")وهادا كود بفكره أخري:
'On the Form with one command button: '**********************************' Private Sub Command1_Click() EnumWindows AddressOf EnumWindowsProc, ByVal 0& End Sub 'In a module: '**********************************' Public Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Boolean Private Declare Function GetProp Lib "user32" Alias "GetPropA" _ (ByVal hwnd As Long, _ ByVal lpString As String) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" _ (ByVal hwnd As Long, _ lpdwProcessId As Long) As Long Private Declare Function OpenProcess Lib "Kernel32.dll" _ (ByVal dwDesiredAccessas As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" _ (ByVal hProcess As Long, _ ByVal uExitCode As Long) As Long Private Const PROCESS_TERMINATE As Long = (&H1) Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim Ret As Long Let Ret = GetProp(hwnd, "CloseNow") If Ret = 1 Then GetWindowThreadProcessId hwnd, PID Ret = OpenProcess(PROCESS_TERMINATE, 0, PID) TerminateProcess Ret, 0 End If EnumWindowsProc = True End Function
أرجو أن تدلونا علي الحل الله يوفقكم
