我目前正在从我的主 vbscript 运行一个新的 vbscript,方法是从字符串数组“即时”创建第二个脚本并将其写入外部secondfile.vbs
文件,然后WshShell.Run "C:\secondfile.vbs"
在第一个运行时使用我需要它来继续运行。
我遇到的问题是,因为我必须重复很多次,所以使用 FSO 编写新的 vbs 文件会稍微减慢这个过程 - 我正试图消除它。有没有办法在不创建物理文件的情况下从内存中运行 vbscript?寻找一种将我的脚本作为字符串并直接作为独立的 vbscript 执行的方法。在此先感谢您的任何建议。
以下是其当前工作方式的简化代码:
Option Explicit
'this is the main RhinoScript file
Call MainRhinoScript()
Sub MainRhinoScript()
'create Wscript.Shell object
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject"):
'get or create user settings plugin folder and vbs file path string
Dim strVBSEventWatcherFile : strVBSEventWatcherFile = "C:\eventwatcher.vbs"
Do
'create auto-generated vbs file here and run it
Call WriteVBS_EventWatcher_File(strVBSEventWatcherFile,
Call WshShell.Run(strVBSEventWatcherFile)
'The main code goes here, looped until done.
'VBS eventwatcher script file is running simultaneously.
Loop
End Sub
'this is simplified VBS writing subroutine to demonstrate how the code works, the actual one is much longer:
Private Sub WriteVBS_EventWatcher_File(strFilePath)
Dim i,fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim file : Set file = fso.CreateTextFile(strFilePath, True)
file.WriteLine("Option Explicit")
file.WriteLine("")
file.WriteLine("Call Main()")
file.WriteLine("Sub Main()")
file.WriteLine(" Dim WshShell : Set WshShell = CreateObject(""WScript.Shell"")'create shell script object")
file.WriteLine("WScript.Sleep 10")
file.WriteLine("WshShell.SendKeys ""Rhino_Preselect "" ")
file.WriteLine("End Sub")
file.Close()
End Sub