以编程方式启用(安装)IIS

时间:2015-08-19 13:45:04

标签: c# .net iis installation installshield

有时候PC上没有IIS。它已禁用或未安装。在这种情况下,我需要自己启用according to those steps

我正在尝试创建将检查IIS是否已启用(已安装)的应用程序,如果没有,则会启用(安装)它。

我尝试使用.msi files from here安装IIS,但它要求我在安装之前关注those stpes

我尝试使用Advanced Installer,但显然它安装了IIS 8.0 Express,但仍然禁用了IIS。

enter image description here

我需要以编程方式启用IIS吗?如果我需要运行IIS安装文件来完成它(我找不到合适的),也是可以接受的。

4 个答案:

答案 0 :(得分:10)

您可以通过命令行安装IIS。以下命令将在Windows 8上安装IIS(您可以对其进行编辑以添加/删除某些功能。它只是我过去使用的命令):

PKGMGR:

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-ApplicationDevelopment;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-NetFxExtensibility45;IIS-ASPNET45;IIS-NetFxExtensibility;IIS-ASPNET;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

DISM:

START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService /FeatureName:IIS-Metabase /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ODBCLogging /FeatureName:IIS-Performance /FeatureName:IIS-RequestFiltering /FeatureName:IIS-RequestMonitor /FeatureName:IIS-Security /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-StaticContent /FeatureName:IIS-URLAuthorization /FeatureName:IIS-WebDAV /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-WMICompatibility /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ProcessModel /FeatureName:WAS-WindowsActivationService

在C#中,您可以创建一个执行此命令的Process,如下所示:

string command = "the above command";
ProcessStartInfo pStartInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
Process p = new Process();
p.StartInfo = pStartInfo;
p.Start();

答案 1 :(得分:1)

您使用InstallShield标记了您的问题,因此我提到InstallShield的更高版本支持启用Windows功能:

Enabling Windows Roles and Features During a Suite/Advanced UI Installation

那就是说,我通常不喜欢这样做,因为你真的很容易干扰PC的配置。我更喜欢创建所需功能的检查,如果不是,则会阻止。

另一个想法是ASP.NET 5.0现在支持自托管,就像过去的其他技术一样。简单地放弃对IIS的需求并以此方式解决问题可能是有意义的。

答案 2 :(得分:1)

关于您使用Advanced Installer的体验。您最终安装了IIS Express,因为您使用了我们预定义的先决条件支持。您应该使用install Windows Feature Bundles的预定义支持。

使用此支持,您可以轻松选择应启用的操作系统功能,还可以设置自定义条件。在我们的YouTube频道上,您可以找到示例/教程:

答案 3 :(得分:0)

您可以从命令行安装IIS。首先,您需要启用ASP.NET 3.5:

IIS-ASPNET;IIS-NetFxExtensibility;NetFx4Extended-ASPNET45

或4.5:

IIS-ASPNET45;IIS-NetFxExtensibility45;NetFx4Extended-ASPNET45

之后你可以安装IIS8,基本上就像IIS7一样。检查IIS7安装http://www.iis.net/learn/install/installing-iis-7/installing-iis-from-the-command-line