【问题标题】:How to install IIS in windows 2008 windows by C#如何通过C#在windows 2008 windows中安装IIS
【发布时间】:2013-04-29 13:52:56
【问题描述】:

我得到一个批处理文件,其中包含:

start /w dism /online /enable-feature /featurename:IIS-WebServerRole
start /w dism /online /enable-feature /featurename:IIS-WebServer
start /w dism /online /enable-feature /featurename:IIS-IIS6ManagementCompatibility
start /w dism /online /enable-feature /featurename:IIS-Metabase
start /w dism /online /enable-feature /featurename:IIS-ManagementService
start /w dism /online /enable-feature /featurename:IIS-HttpRedirect
start /w dism /online /enable-feature /featurename:IIS-RequestMonitor
start /w dism /online /enable-feature /featurename:IIS-BasicAuthentication
start /w dism /online /enable-feature /featurename:IIS-WindowsAuthentication
start /w dism /online /enable-feature /featurename:IIS-ISAPIExtensions
start /w dism /online /enable-feature /featurename:IIS-ASP
start /w dism /online /enable-feature /featurename:IIS-ISAPIFilter

rem WIN 8 Only
start /w dism /online /enable-feature /featurename:NetFx3
start /w dism /online /enable-feature /featurename:NetFx4Extended-ASPNET45

start /w dism /online /enable-feature /featurename:IIS-NetFxExtensibility
start /w dism /online /enable-feature /featurename:IIS-ASPNET
start /w dism /online /enable-feature /featurename:IIS-ServerSideIncludes

rem WIN 8 Only
start /w dism /online /enable-feature /featurename:IIS-NetFxExtensibility45
start /w dism /online /enable-feature /featurename:IIS-ASPNET45


echo IIS installation complete

将从 Internet 下载 IIS 并安装在本地计算机上。我使用 C# 代码将其称为installiis.bat。代码是

batchCommand = installiis.bat;
procStartInfo = new ProcessStartInfo();
procStartInfo.WorkingDirectory = targetDir;
procStartInfo.FileName = batchCommand;
procStartInfo.Arguments = argument;//this is argument
procStartInfo.CreateNoWindow = true;
procStartInfo.UseShellExecute = true;
procStartInfo.Verb = "runas";

proc.StartInfo = procStartInfo;
proc.Start();

proc.WaitForExit();

此代码在win7和其他平台下完美运行,但无法使用Windows 2008 Serverwindows 8中的C#代码启动批处理文件。命令窗口在启动后立即消失。但是当我手动单击并以管理员身份运行时,相同的批处理文件可以正常工作。请任何人提供任何解决方案。

【问题讨论】:

  • 您是否尝试过使用管理权限执行您的 C# 应用程序?
  • 感谢@gustavodidomenico。这行得通。

标签: c# windows iis-7 batch-file


【解决方案1】:

我认为您必须将应用程序清单添加到您的程序中才能为您的应用程序请求提升的权限。

http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 2016-09-11
    相关资源
    最近更新 更多