Access a VB script object from executed C# application
A VBScript are loaded within another application, the application thats loading/executing the VBScript are creating an object so it's possible to get and set variables to and from the application loading the VBScript.
In the loaded VBScript I'm reading a variable with the following command:
ApplicationName.GetStringVariable("string1")
I'm executing my C# application from the VBScript with the following commnand:
Set WshShell = CreateObject("WScript.Shell")
Return = WshShell.Run("c:\TestAppDelete.exe", 1, true)
I use the bWaitOnReturn so that the VBScript are running while my other C# application are running. But I can't find a way to access this VBScript object from my C# application. It tells me the object are not existing. Th开发者_高级运维is is my C# code:
I'm executing an exe from a VBScript with the following code trying to access the VBScript object:
MSScriptControl.ScriptControlClass sc = new MSScriptControl.ScriptControlClass();
sc.Language = "VBScript";
sc.AddCode("MsgBox ApplicationName.GetStringVariable(\"string1\")");
What am I doing wrong?
When you run the TestAppDelete.exe
you create a fresh new process. When you create a ScriptControlClass
you create a fresh new scripting context in your fresh new process. When you add code to that script that uses ApplicationName
that object doesn't exist and therefore fails.
Instead of creating a C# .exe consider creating a COM compatible C# .dll instead.
精彩评论