How to call a VBScript file in a C# application? How to call a VBScript file in a C# application? asp.net asp.net

How to call a VBScript file in a C# application?


The following code will execute a VBScript script with no prompts or errors and no shell logo.

System.Diagnostics.Process.Start(@"cscript //B //Nologo c:\scripts\vbscript.vbs");

A more complex technique would be to use:

Process scriptProc = new Process();scriptProc.StartInfo.FileName = @"cscript"; scriptProc.StartInfo.WorkingDirectory = @"c:\scripts\"; //<---very important scriptProc.StartInfo.Arguments ="//B //Nologo vbscript.vbs";scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping upscriptProc.Start();scriptProc.WaitForExit(); // <-- Optional if you want program running until your script exitscriptProc.Close();

Using the StartInfo properties will give you quite granular access to the process settings.

You need to use Windows Script Host if you want windows, etc. to be displayed by the script program. You could also try just executing cscript directly but on some systems it will just launch the editor :)


Another approach is to create a VB.NET Class Library project, copy your VBScript code into a VB.NET Class file, and reference the VB.NET Class Library from your C# program.

You will need to fix-up any differences between VBScript and VB.NET (should be few).

The advantage here, is that you will run the code in-process.


This is a permissions issue. Your application appPool must be running at the highest permission level to do this in 2008. The Identity must be Administrator.