使用WScript访问从C#调用VBScript

时间:2017-11-10 11:18:12

标签: c# vbscript

使用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对象的实例?

1 个答案:

答案 0 :(得分:0)

您不需要/无法将wscript.exe / cscript.exe主机提供的WScript对象提供给ScriptControl。只需使用普通CreateObject即可。请参阅here