- Public Const ErrorSuccess = 0
- Public Const ProcessAllAccess = 2035711
-
- ' ### FUNCTION ###
- ' ===============================================================================================
- ' Name.................... : SuspendProcess()
- ' Description........... : Suspend/Resume a process specified.
- ' Requirements........ : DynWrap.dll -
- ' : Kernel32.dll - OpenProcess
- ' : - CloseHandle
- ' : Ntdll.dll - NtResumeProcess
- ' : - NtSuspendProcess
- ' Syntax................... : SuspendProcess(iProcess, iFlag)
- ' Parameters............ : iProcess - PID or Image name for a process.
- ' : iFlag - Set this parameter to True to suspend a process, otherwise resume.
- ' Return values........ : Success - ErrorSuccess
- ' : Failure - 1, Process is not found.
- ' Author.................. : Pusofalse
- ' Modified............... :
- ' Remarks................ : To suspend process will lead the process is not responding.
- ' Related.................. :
- ' Link...................... :
- ' Examples............... : Suspend : SuspendProcess "notepad.exe", True
- ' : Resume : SuspendProcess "notepad.exe", False
- ' ===============================================================================================
- Function SuspendProcess(iProcess, iFlag)
- Dim oProcess, oItem, sWMI, i_Flag
- Set oProcess = GetObject("winmgmts:\\.\root\cimv2")
- If not IsNumeric(iProcess) then
- sWMI = "Select ProcessId From Win32_Process where Name='" & iProcess & "'"
- Set oItem = oProcess.ExecQuery(sWMI, , 48)
- For Each ele In oItem
- iProcess = ele.ProcessId
- Next
- End If
- If not IsNumeric(iProcess) then
- SuspendProcess = 1
- Exit Function
- End If
- Dim hProcess, NtProcess, iResult
- Set NtProcess = CreateObject("DynamicWrapper")
- NtProcess.Register "kernel32.dll", "OpenProcess", "i=luu", "r=h"
- NtProcess.Register "kernel32.dll", "CloseHandle", "i=h", "r=u"
- NtProcess.Register "Ntdll.dll", "NtSuspendProcess", "i=h", "r=u"
- NtProcess.Register "Ntdll.dll", "NtResumeProcess", "i=h", "r=u"
- hProcess = NtProcess.OpenProcess(ProcessAllAccess, 0, iProcess)
- If iFlag = True Then
- iResult = NtProcess.NtSuspendProcess(hProcess)
- Else
- iResult = NtProcess.NtResumeProcess(hProcess)
- End If
- NtProcess.CloseHandle hProcess
- SuspendProcess = iResult
- Exit Function
- End Function '==> SuspendProcess()
复制代码
|