EDIT
I added in some error handling to my .vbs file and it is indeed a permissions issue (I now get a "Permission Denied error"). However, supplying my credentials in the web.config <impersonate>
tag does not seem to have any effect.
Also when trying to supply my credentials to the process via via
p.StartInfo.Password = Misc.CreateSecurityString("password");
p.StartInfo.UserName = "admin";
I get an new error:
cscript.exe - Application error
The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.
Shout it out if you know what's causing this. (Or just type it...)
Thanks for your help so far!
Background
I'm trying to execute a .vbs file from an custom handler (.ashx). The VBScript is setting up a web application in iis 5.1.
So far the following code executes without errors
string sToRun = "C:\CreateIISApplication.vbs"
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cscript";
p.StartInfo.Arguments = sToRun;
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string sOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Problem
My problem is that the vbscript appears to not have run at all. When I check IIS, my application is not created.
When I run the script file directly from the command prompt everything works correctly and my application shows up in IIS.
Trouble Shooting
I decided to add some echo statements into the .vbs file so I could make sure it was running. On the command line, all the statements are outputted correctly. When checking the string sOutput I get the header message, but none of my subsequent messages.
From C# - contents of sOutput
Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved
From the Command Line
Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved
Hello
So I can prove (I think) that the .vbs file is not being evaluated, and cscript is being called. And if I call cscript without referencing a .vbs file, then I get the help documentation. So something is going wrong.
Any ideas? Thanks!