Vbscript question: running script from another script without creating a file - possible?

Hi All,

I am currently running a new vbscript from my main RhinoScript 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 main RhinoScript is running as well.

The problem I have is, since I have to repeat it many times during runtime, writing the new vbs file using FSO slows the process down a bit on every creation/execution - I am trying to eliminate that. Is there a way to run a vbscript from the memory, without creating a physical file on HD? Looking for a way to get my script as strings and execute directly as independent vbscript. Thanks in advance for any suggestions.


Hi @Jarek, you might try to use execute statement followed by your script as string. eg.:

Call Main()
Sub Main()
    Dim s
    s = "Sub MyRoutine" & vbCrLf
    s = s & "Dim a" & vbCrLf
    s = s & "a = 123" & vbCrLf
    s = s & "Rhino.Print a " & vbCrLf 
    s = s & "End Sub" & vbCrLf 
    s = s & "Call MyRoutine()"
    Execute s
End Sub

A simpler example, if your script would be written into the Notes window, you can just get it as string and run it. Eg. paste this to the Notes window:

Sub MyRoutine
Dim a
a = "Rhino rocks!"
Rhino.Print a
End Sub
Call MyRoutine()

Now run this from your script:

Execute Rhino.Notes()

I am not sure if this all works if you´re inlining this while another script runs, but it might be worth a try :wink:


Hi @Clement,

Thanks a lot for your input. I am testing both Execute and ExecuteGlobal, will see where it takes me.
Btw - nice trick with the notes - I can see how this could be useful with few other scenarios.


This should launch WScript.exe (it is possible that CScript.exe is the default application for running scripts). Both of these executables work by loading script files…

@Jarek, it should work using the clipboard as well. But since you’re writing already using FSO, maybe the same string can just be used to execute…

good luck :wink:


Hi @Dale,
Yes, I guess that’s what is happening now - I am writing the vbs file on the fly from RhinoScript several times during one RhinoScript runtime - saving on HD, and executing with WshShell.Run. Works quite well and does what I need (it acts as another layer of pseudo ‘event-watcher’. What I am trying to do is shave off some time (half second or less per-run) by possibly not writing the file into HD but somehow running it from the memory. Don’t know the way yet to do it and Execute may not let me run vbs simultaneously with the main RhinoScript…


Try RAMDISK :wink:

Nice suggestion, thanks! I have to be able to make in run on systems without a custom software installed, so I need to keep looking…

Ok, but access to memory address with vbs and without external program/dll will never work and even then it is very complicated.