please I have an application that needs IIS to run, now IIS needs to be turned on manually in the windows control panel. But I want to avoid this process and automatically turn on IIS how can I do this. Thank you
-
1Are you talking about turning on the IIS Windows Feature? Is that the control panel you're referring to? If not, which one? And what's your "entry point" for trying to do this? Some form of installer package? (If so, what technology are you using to build it?) – Damien_The_Unbeliever May 22 '18 at 13:33
-
Yes I mean turning on the IIs windows feature in the control panel. I am trying to do it from an installer package. I am using the dot net frame work to build it. – user2135480 May 22 '18 at 16:31
-
By tech, I meant visual studio setup project, Wix, InstallShield, etc. What are you authoring the *setup* project in? – Damien_The_Unbeliever May 22 '18 at 16:54
-
Ok I am using Wix. – user2135480 May 22 '18 at 18:04
-
Similar question wanting to [install MSMQ via WIX](https://stackoverflow.com/q/18126502/15498). The specific package will change for IIS but the general technique should apply. – Damien_The_Unbeliever May 23 '18 at 05:23
1 Answers
The IIS is implemented as a Windows Service. So the only thing necessary is you to make sure the Startup type
of the W3SVC is set to Automatic
. It is set to automatic by default, so your question implies that someone has changed it to one of the other options.
So open the services and look for World Wide Web Publishing Service
. Then double-click on it and you'll be present with its properties. From the Startup type
drop-down choose Automatic
. Restart your computer. The IIS will start automatically.
UPDATE
Based on the OP's comment I assume the re-configuration of the service is necessary.
Unfortunately, there is no managed class to change the service startup type. You can go through P/Invoke and call the native Windows API. Another option is to utilize the WMI. But the quickest way is to spawn a privileged cmd.exe
from your application installer and run the following:
sc config w3svc start=auto
However, this is not a bulletproof solution as someone else might later change it again to demand
or even disabled
.
If you're looking for a mechanism to start the service at the execution of the application installer, you might want the ServiceController
class. It can start the service but it cannot change its startup type. Here is the official documentation.
So you could do something like this in your code:
using (var w3cvs = new ServiceController("W3Svc"))
{
if (w3cvs.Status == ServiceControllerStatus.Stopped)
{
w3cvs.Start();
}
}

- 3,576
- 1
- 18
- 28
-
1Since Automatic is the default start mode for this service after IIS is installed, I'm struggling to work out if this is what the OP means, or if as in my comments they're talking about *installing* IIS, or something else. – Damien_The_Unbeliever May 22 '18 at 14:01
-
From the different divices tested on, iis service was turned off. So I am looking for a way to turn it on through the application installer package. Without going into WWW publishing services – user2135480 May 22 '18 at 16:34