I am currently running a new vbscript from my main vbscript by creating the 2nd script 'on the fly' from array of strings and writing it to external secondfile.vbs
file, then using WshShell.Run "C:\secondfile.vbs"
I need it to keep running while the 1st one is running as well.
The problem I have is, since I have to repeat it many times, writing the new vbs file using FSO slows the process down a bit - I am trying to eliminate that. Is there a way to run a vbscript from the memory, without creating a physical file? Looking for a way to get my script as strings and execute directly as independent vbscript. Thanks in advance for any suggestions.
Here is a simplified code of how it currently works:
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