Programmatically enable (install) IIS
Asked Answered
M

4

13

Sometimes there is a PC that doesn't have IIS. Either it disabled or either it not installed. In this case I need to enable it myself according to those steps.

I'm trying to create application that will check if IIS is enabled (installed), and if not it will enable (install) it.

I tried to install IIS using .msi files from here, but it asking me to follow those stpes before the installation.

I tried to use Advanced Installer but apparently it installing the IIS 8.0 Express but still it keeps the IIS disabled.

enter image description here

What I need to do to enable IIS programmatically? It is also acceptable if I'll need to run an IIS installation file to make it done (I didn't find the right one).

Myrlemyrlene answered 19/8, 2015 at 13:45 Comment(0)
M
20

You can install IIS via the command line. The following command will install IIS on Windows 8 (you can edit this to add/remove certain features. It's just a command I've used in the past):

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

In C#, you can create a Process that executes this command like so:

string command = "the above command";
ProcessStartInfo pStartInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
Process p = new Process();
p.StartInfo = pStartInfo;
p.Start();
Marmoreal answered 19/8, 2015 at 13:59 Comment(8)
PkgMgr was deprecated years ago. Microsoft suggests using DISM /Online instead.Vesta
Fair point, but the issue I've found with DISM is that requires you to restart the machine when installing IIS. If installing IIS programmatically is being done to save the hassle of a manual installation (which it seems is the case), I can't imagine restarting the machine every time you run the command is a desirable alternative. I haven't come across a way to install IIS via DISM without a restart, but if there is a way to do so, I'd like to know.Marmoreal
Have you passed the /NoRestart switch?Vesta
Yeah, it just suppresses the "Do you want to restart now? y/n" message after the tool has run, but a restart is still required before IIS is enabled.Marmoreal
I'd take the reboot then. Windows defers OS level configurations and it may very well be needed. When I install IIS it's typically a server so I want the reboot anyways to make sure things like patching, GPO, SCCM cycles and so on all run. I'm all for consolidating and avoiding reboots where possible but IIS is a pretty big change to a machine.Vesta
Hi @Oliver Nicholls, your answer pointed me to the right command (cmd command) witch can enable what ever I need. I'm using Windows 7 and here is the command that I ran in my cmd directly and it worked perfectly (command placed in question). But when I'm running this command using your code example the cmd window pops up and I'm getting the following error: "Operation failed with 0x8007000B An attempt was to load a program with an incorrect format." What causing this error?Myrlemyrlene
I haven't come across this issue before, unfortunately. I don't think it's an issue with the code though. Perhaps you could try one of the solutions here: #2024266 which seem to suggest that the issue is with your IDE settings or application pool settings. Sorry I can't be of more help, I tried to get the same error message as you, but can't seem to get it.Marmoreal
Also, for the sake of completion, I'll include the DISM command in my original answer too.Marmoreal
E
1

You can install IIS from command line. First you need to enable ASP.NET 3.5:

IIS-ASPNET;IIS-NetFxExtensibility;NetFx4Extended-ASPNET45

or 4.5:

IIS-ASPNET45;IIS-NetFxExtensibility45;NetFx4Extended-ASPNET45

After that you can install IIS8, basically like IIS7. Checkout the IIS7 instalation http://www.iis.net/learn/install/installing-iis-7/installing-iis-from-the-command-line

Empoverish answered 19/8, 2015 at 14:0 Comment(0)
V
1

You tag your question with InstallShield so I mention that later versions of InstallShield have support for enabling windows features:

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

That said, I don't typically like to do this because you are really be intrusive with the configuration of the PC. I prefer to author a check that the required features are installed and block if they aren't.

Another thought is that ASP.NET 5.0 now supports self hosting as have other technologies such as WCF in the past. It might make sense to simply ditch the need for IIS and kill the problem that way.

Vesta answered 19/8, 2015 at 18:10 Comment(0)
A
1

Regarding your experience with Advanced Installer. You ended up with IIS Express installed because you used our predefined support for prerequisites. You should have been using the predefined support to install Windows Feature Bundles.

Using this support you can easily select which OS feature should be enabled and also set custom conditions. On our YouTube channel you can find examples/tutorials:

Armilda answered 20/8, 2015 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.