Board logo

标题: [原创] vbs 暂停/恢复进程 [打印本页]

作者: pusofalse    时间: 2009-3-12 17:49     标题: [原创] vbs 暂停/恢复进程

  1. Public Const ErrorSuccess = 0
  2. Public Const ProcessAllAccess = 2035711
  3. ' ### FUNCTION ###
  4. ' ===============================================================================================
  5. ' Name.................... : SuspendProcess()
  6. ' Description........... : Suspend/Resume a process specified.
  7. ' Requirements........ : DynWrap.dll   -
  8. '  : Kernel32.dll   - OpenProcess
  9. '  :    - CloseHandle
  10. '  : Ntdll.dll    - NtResumeProcess
  11. '  :    - NtSuspendProcess
  12. ' Syntax................... : SuspendProcess(iProcess, iFlag)
  13. ' Parameters............ : iProcess    - PID or Image name for a process.
  14. '  : iFlag    - Set this parameter to True to suspend a process, otherwise resume.
  15. ' Return values........ : Success    - ErrorSuccess
  16. '  : Failure    - 1, Process is not found.
  17. ' Author.................. : Pusofalse
  18. ' Modified............... :
  19. ' Remarks................ : To suspend process will lead the process is not responding.
  20. ' Related.................. :
  21. ' Link...................... :
  22. ' Examples............... : Suspend : SuspendProcess "notepad.exe", True
  23. '  : Resume : SuspendProcess "notepad.exe", False
  24. ' ===============================================================================================
  25. Function SuspendProcess(iProcess, iFlag)
  26. Dim oProcess, oItem, sWMI, i_Flag
  27. Set oProcess = GetObject("winmgmts:\\.\root\cimv2")
  28. If not IsNumeric(iProcess) then
  29.   sWMI = "Select ProcessId From Win32_Process where Name='" & iProcess & "'"
  30.   Set oItem = oProcess.ExecQuery(sWMI, , 48)
  31.   For Each ele In oItem
  32.    iProcess = ele.ProcessId
  33.   Next
  34. End If
  35. If not IsNumeric(iProcess) then
  36.   SuspendProcess = 1
  37.   Exit Function
  38. End If
  39. Dim hProcess, NtProcess, iResult
  40. Set NtProcess = CreateObject("DynamicWrapper")
  41. NtProcess.Register "kernel32.dll", "OpenProcess", "i=luu", "r=h"
  42. NtProcess.Register "kernel32.dll", "CloseHandle", "i=h", "r=u"
  43. NtProcess.Register "Ntdll.dll", "NtSuspendProcess", "i=h", "r=u"
  44. NtProcess.Register "Ntdll.dll", "NtResumeProcess", "i=h", "r=u"
  45. hProcess = NtProcess.OpenProcess(ProcessAllAccess, 0, iProcess)
  46. If iFlag = True Then
  47.   iResult = NtProcess.NtSuspendProcess(hProcess)
  48. Else
  49.   iResult = NtProcess.NtResumeProcess(hProcess)
  50. End If
  51. NtProcess.CloseHandle hProcess
  52. SuspendProcess = iResult
  53. Exit Function
  54. 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