标题: [原创] vbs 暂停/恢复进程 [打印本页]
作者: pusofalse 时间: 2009-3-12 17:49 标题: [原创] vbs 暂停/恢复进程
- 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()
复制代码
作者: 523066680 时间: 2009-3-16 10:45
pusofalse 的vbs 到这程度拉 仰慕一下 顺便顶帖。
作者: slore 时间: 2009-3-18 17:57
Set NtProcess = CreateObject("DynamicWrapper")
3方....
VBS望...API
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |