Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute VBScript in C#

Tags:

c#

vbscript

We have a legacy system that allow customer to custmize the workflow by vbscript, for example, the user could write some code like

for each account in accounts {
   Dim acc as Integer
   .....
}

the code inside the {...} is VBScript. and the legacy system is writtern by VB, and use ScriptControl to execute the script directly. Now we are going to upgrade the system to C# .NET 4.5, we want to get rid of the old scriptcontrol but want to keep the scripts from users.

My question is it possible to execute vb script from C#?

Thanks

like image 721
Sean Avatar asked Sep 09 '26 09:09

Sean


2 Answers

You can execute VBScript from C# code.

Process scriptProc = new Process();
scriptProc.StartInfo.FileName = @"C:\text.vbs";
scriptProc.Start();
scriptProc.WaitForExit();
scriptProc.Close();

There are some important things that you have to consider. Take a look at this answer

like image 120
diyoda_ Avatar answered Sep 11 '26 21:09

diyoda_


finally, we decide to migrate to IronPython instead of VBS, vbs is not supported by microsoft. so it's time for move on

like image 37
Sean Avatar answered Sep 11 '26 23:09

Sean