使用COM MSScriptControl的C#代码:
var script = new MSScriptControl.ScriptControl();
script.Language = "VBScript";
script.AddObject("me", this, true);
//script.AddObject("WScript", wscript, true);
script.AddCode(System.IO.File.ReadAllText("Script.vbs"));
Script.vbs内容:
Set oShell = WScript.CreateObject ("WScript.Shell")
错误:Objet请求:'WScript'
如何在C#中为addobject创建WScript对象的实例?
答案 0 :(得分:0)
您不需要/无法将wscript.exe / cscript.exe主机提供的WScript对象提供给ScriptControl。只需使用普通CreateObject
即可。请参阅here。