I have a program that installs a service, and I'd like to be able to give the user the option later on to change the startup type to "Automatic".
The OS is XP - if it makes any difference (Windows APIs?).
How can I do this in .NET? C# if possible! :)
I check all my machines, include Server 2012R2, Server 2016 and Server 2019, even 2 Windows 10 machines, the Startup type of Windows update service on all of devices are Manual, not Automatic or Automatic Delayed Start.
In your Installer class, add a handler for the AfterInstall event. You can then call the ServiceController in the event handler to start the service. Now when you run InstallUtil on your installer, it will install and then start up the service automatically.
I wrote a blog post on how to do this using P/Invoke. Using the ServiceHelper class from my post you can do the following to change the Start Mode.
var svc = new ServiceController("ServiceNameGoesHere"); ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With