Run VBScript using C#

2020-03-29 08:21发布

I am trying to execute a script written in VBScript, in a C# class library project

using System.Web.UI;  //reference added at top

MSScriptControl script = new ScriptControl();
script.Language = "VBScript";
script.AddObject("Repository", connectToDB.GetRepository);  

I get the following compilation error:

Error CS0246: The type or namespace name 'MSScriptControl' could not be found (are you missing a using directive or an assembly reference?)

Any ideas?

2条回答
Juvenile、少年°
2楼-- · 2020-03-29 08:32

I belive

MSScriptControl script = new ScriptControl();

should be

MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
查看更多
来,给爷笑一个
3楼-- · 2020-03-29 08:41
  1. Add a COM reference of "Microsoft Script Control 1.0" to your project.
  2. using Microsoft.VisualBasic;
  3. Use this code: ​​

    MSScriptControl.ScriptControl script = new MSScriptControl.ScriptControl();
    script.Language = "VBScript";
    script.AddObject("Repository", connectToDB.GetRepository); 
    
查看更多
登录 后发表回答