nuander
nuander

Reputation: 1423

How to call a VBS script from C# managed code

You would think this would be simple... From the command line I can execute

c:\windows\system32\cscript c:\windows\system32\iisext.vbs /ListFile

But when I try it from managed code...

Process proc = new Process();
proc.StartInfo.FileName = @"c:\windows\system32\cscript";
proc.StartInfo.Arguments = @"c:\windows\system32\iisext.vbs /ListFile";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
using (StreamReader sr = proc.StandardOutput) {
...

I get this error:

Input Error: Can not find script file "c:\windows\system32\iisext.vbs"

What am I missing?

Thanks

Upvotes: 0

Views: 376

Answers (1)

EricLaw
EricLaw

Reputation: 57115

Hans is correct; the problem is almost certainly that you're running in 32bit mode, which means that C:\windows\system32 doesn't point where you think. (Verify by watching file access with Process Monitor).

Use C:\windows\sysnative instead, or compile your app to target AnyCPU.

Upvotes: 2

Related Questions