I am trying to distribute IIS Express with my application. IIS Express will serve external web requests on port 80.
I have no problems running IIS Express as well as serving external requests however Microsoft in their infinite wisdom decided to run IIS Express from a console window as well as a system tray item. You can disable the tray item by a command line argument but not the console window.
I want to run IIS Express without the console window being displayed. I also want to run IIS Express from a windows service.
Running the following code from within my application does exactly what I want:
Directory.SetCurrentDirectory(string.Format("{0}\\IIS Express", iisProgramDirectory));
process.EnableRaisingEvents = true;
//process.Exited += new EventHandler(process_Exited);
process.StartInfo.FileName = "iisexpress.exe";
process.StartInfo.Arguments = string.Format("\"/config:{0}webservice\\config\\applicationhost.config\"", dataDirectory);
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//process.StartInfo.UserName = "Administrator";
//System.Security.SecureString securePwd = new System.Security.SecureString();
//string password = "**********";
//char[] pword = password.ToCharArray();
//for (int i = 0; i < pword.Length; i++)
//{
// securePwd.AppendChar(pword[i]);
//}
//process.StartInfo.Password = securePwd;
process.Start();
Obviously I am running as Administrator. IIS Express apparently needs to run with Administrator privileges to serve external requests as well as listen on port 80.
My windows service runs under the Windows Service account which I believe has full privileges but the IIS Express process just gracefully exits with an error code of 0 when I try to run it from the windows service.
I have tried a number of scenarios (as you can see from the code snippet) but there seems to be no way I can get IIS Express running using my windows service AND hide the darn console window.
Any suggestions will be appreciated.