带有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"));
脚本.vbs 内容:
Set oShell = WScript.CreateObject ("WScript.Shell")
错误:对象要求:"WScript">
如何在 C# 中为 addobject 创建 WScript 对象的实例?
你不需要/不能将 wscript.exe/cscript.exe 主机提供的 WScript 对象提供给 ScriptControl。只需使用普通CreateObject
.看这里。