如何通过Windows服务将IIS Express作为进程运行 [英] How to run IIS Express as a process started via a Windows Service

查看:61
本文介绍了如何通过Windows服务将IIS Express作为进程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将IIS Express与我的应用程序一起分发. IIS Express将在端口80上处理外部Web请求.

I am trying to distribute IIS Express with my application. IIS Express will serve external web requests on port 80.

我在运行IIS Express以及处理外部请求方面都没有问题,但是Microsoft出于无限的智慧,决定从控制台窗口和系统任务栏中运行IIS Express.您可以通过命令行参数而不是控制台窗口来禁用任务栏项目.

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.

我想在不显示控制台窗口的情况下运行IIS Express.我还想从Windows服务运行IIS Express.

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();

很明显,我以管理员身份运行. IIS Express显然需要以管理员权限运行,以服务外部请求以及在端口80上进行侦听.

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.

我的Windows服务在Windows服务帐户下运行,我认为它具有全部特权,但是当我尝试从Windows服务运行IIS Express进程时,IIS Express进程仅以错误代码0正常退出.

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.

我已经尝试了多种方案(如您从代码片段中看到的),但是似乎无法使用Windows服务使IIS Express运行并隐藏darn控制台窗口.

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.

任何建议将不胜感激.

推荐答案

如果您还想使用端口80,则无法完成此操作.

It can't be done if you also want to use Port 80.

这篇关于如何通过Windows服务将IIS Express作为进程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆