我有一个VBS脚本(实际上编译为.exe ),它使用VBS运行指令调用另一个程序(.exe)。我的大型机心态告诉我,在我的脚本开始时预加载这个第二个程序是有益的,这样在需要的时候它就可以使用了。通常在大型机上,在适当的情况下,人们会在某个时候将程序加载到内存中,然后稍后再转到内存中。
这个概念是否存在于VBS中?
谢谢你的建议。
发布于 2017-02-11 13:59:53
在暂停状态下启动程序是很容易的,但是我仍然没有找到一种方法来在没有外部工具的情况下恢复执行(我们需要调用ResumeThread API)。对于这个示例,我使用了Windows的PsSuspend工具来恢复这个过程。
Option Explicit
Const SW_NORMAL = 1
Const CF_CREATE_SUSPENDED = 4
Const PROCESS_NAME = "Notepad.exe"
' Instantiate required objects
Dim wmi, shell
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set shell = WScript.CreateObject("WScript.Shell")
' Prepare the startup configuration for the process
' https://msdn.microsoft.com/en-us/library/aa394375%28v=vs.85%29.aspx
Dim startUp
Set startUp = wmi.Get("Win32_ProcessStartup").SpawnInstance_
With startUp
.ShowWindow = SW_NORMAL
.CreateFlags = CF_CREATE_SUSPENDED
End With
' Start the process
' https://msdn.microsoft.com/en-us/library/aa394372%28v=vs.85%29.aspx
Dim retCode, processID
retCode = wmi.Get("Win32_Process").Create( PROCESS_NAME, Null, startUp, processID )
If retCode <> 0 Then
Wscript.Echo "Process creation failed: " & retCode
WScript.Quit 1
End If
WScript.Echo "Process created with PID: " & processID
' Ask the OS to check for presence of our process
WScript.Echo shell.Exec("tasklist /fo:list /v /fi ""imagename eq " & PROCESS_NAME & """").StdOut.ReadAll()
' Wait (not required, just for testing)
WScript.Sleep 5000
' Resume the process - SysInternals pssuspend required
' https://technet.microsoft.com/en-us/sysinternals/pssuspend.aspx
Call shell.Run("pssuspend64.exe /accepteula -r " & processID, 0, False)
' Wait for the process to resume and show again the task list
WScript.Sleep 2000
WScript.Echo shell.Exec("tasklist /fo:list /v /fi ""imagename eq " & PROCESS_NAME & """").StdOut.ReadAll()https://stackoverflow.com/questions/42149958
复制相似问题