[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[原创] 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()
复制代码
1

评分人数

心绪平和,眼藏静谧。

Set NtProcess = CreateObject("DynamicWrapper")

3方....

VBS望...API

TOP

pusofalse 的vbs 到这程度拉  仰慕一下 顺便顶帖。

TOP

返回列表