اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

use api function TerminateProcess to kill process - استخدام دالة TerminateProcess لقتل العمليات


SEMO.Pa3x

الردود الموصى بها

السلام عليكم، كما في العنوان شرح استخدام دالة TerminateProcess
لقتل العمليات..

اولا: الدوال المُستخدم بالشرح
TerminateProcess , FindWindow , GetWindowThreadProcessId , CloseHandle , OpenProcess


تصريح الدالة:

Declare Auto Function TerminateProcess Lib "KERNEL32.DLL" (ByVal hProcess As IntPtr, ByVal uExitCode As UInteger) As Boolean

 

الدالة تحتاج الى براميترات 2
الاول: مقبض العملية
الثاني: قيمة رقمية، نضع 0 لتمثل قتل العملية

فيكون الاستدعاء بالشكل العام هكذا

 

TerminateProcess(hwd, 0)


hwd= تمثل المقبض


------------------------------------------------------------
كيفية الحصول على مقبض للعمليات ؟؟
------------------------------------------------------------

هناك عدة طرق اسهلها، استخدام دالة FindWindow

تصريح الدالة:

 

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

 


استدعاء الدالة:

 

Dim hwd As IntPtr = FindWindow(Nothing, "WindowTitle")

 

الدالة تحتاج براميترات 2
الاول: اسم كلاس النافذة بامكانك كتابة استخراج اسم الكلاس بواسطة اداة AutoIt Window Info
او اداة ++Spy التي تأتي مع فيجوال دوت نت.

البراميتر الثاني: عنوان النافذة (العنوان المكتوب فوق النافذة للبرنامج)

بأمكانك كتابة احد هذه البراميترات وتعويض البراميتر الثاني بـ Nothing
 

----------------------------------------------------------------------------------------------------

او استخدام طريقة اكثر بساطة وبدون api
------------------------------------------------------------

 

For Each x As Process In Process.GetProcessesByName("NameYourProcess")
MsgBox(x.Handle)
Next

 

بعد ان تعلمنا كيفية جلب المقبض للعملية ، نأتي الى تكملة شرحنا في استدعاء الدالة
صرح الدوال الاتية مع الستركشر الخاص بدالة OpenProcess

 

Declare Auto Function TerminateProcess Lib "KERNEL32.DLL" (ByVal hProcess As IntPtr, ByVal uExitCode As UInteger) As Boolean
 <DllImport("user32.dll", SetLastError:=True)> _
 Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
 End Function
 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
 Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As ProcessAccessFlags, bInheritHandle As Boolean, processId As UInt32) As IntPtr
 <DllImport("kernel32.dll", SetLastError:=True)> _
 Private Shared Function CloseHandle(ByVal hHandle As IntPtr) As Boolean
 End Function
 <Flags>
 Public Enum ProcessAccessFlags As UInteger
 All = &H1F0FFF
 Terminate = &H1
 CreateThread = &H2
 VirtualMemoryOperation = &H8
 VirtualMemoryRead = &H10
 VirtualMemoryWrite = &H20
 DuplicateHandle = &H40
 CreateProcess = &H80
 SetQuota = &H100
 SetInformation = &H200
 QueryInformation = &H400
 QueryLimitedInformation = &H1000
 Synchronize = &H100000
 End Enum

 

استدعاء الدالة وقتل العملية:
 

 

Dim TPID, TPHWD As Integer
 
 ' Get the process ID.
 TPID = 0
 GetWindowThreadProcessId(HWND, TPID) ' Replace HWND with your handle process
 
 ' Open the process.
 TPHWD = OpenProcess(ProcessAccessFlags.Synchronize Or ProcessAccessFlags.Terminate, 0, TPID)
 
 ' Terminate the process.
 TerminateProcess(TPHWD, 0)
 
 ' Close the process.
 CloseHandle(TPHWD)

 

استبدل HWND بمقبض العملية اي:
 

 

Dim TPID, TPHWD As Integer
 
  ' Get the process ID.
  TPID = 0
  GetWindowThreadProcessId(FindWindow(Nothing, "Untitled - Notepad"), TPID) ' Replace HWND with your handle process
 
  ' Open the process.
  TPHWD = OpenProcess(ProcessAccessFlags.Synchronize Or ProcessAccessFlags.Terminate, 0, TPID)
 
  ' Terminate the process.
  TerminateProcess(TPHWD, 0)
 
  ' Close the process.

 


على سبيل المثال طبقت على المفكرة
اي سؤل اني موجود
تحياتي

 

 

تم بحمد الله ، SEMO.Pa3x

:38:

  • Thanks 1
رابط هذا التعليق
شارك

  • 1 year later...

السلام عليكم ورحمة الله 

موضوع في غاية الاهمية 

انا عندي كود يقوم بإغلاق جميع العمليات اللي شغاله على الحاسب تمام .. وده كويس وفعال // لكن انا عايز الغي كل العمليات على الجهاز ما عدا كذا وكذا وكذا .

مع العلم اني اشتغل على الاكسيس 

 

رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • اضف...

Important Information