Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a service with the delayed-auto startup type in Windows XP

My installer creates services with the following command in Inno Setup:

Filename: {sys}\sc.exe; Check: IsAdminLoggedOn; Parameters: "create Example start= delayed-auto binPath= ""{app}\Example.exe"""; Flags: runhidden

This line works in all Windows besides Windows XP because the delayed-auto startup type is not supported in Windows XP.
I need to use the delayed-auto startup type for two reasons.

  1. My service needs to always run on the background without user intervention, which means that the service must automatically start on boot.
  2. My service depends on other basic windows services and cannot run without them, therefor I use the delayed-auto to start only after all the basic services are up.

So can I create a service on Windows XP that has a startup type similar to that of delayed-auto and if not then what are the alternatives?

like image 284
yuval Avatar asked Sep 14 '25 20:09

yuval


1 Answers

The delayed-auto startup type is not intended to resolve dependency between services. What if the services you depend on also had delayed-auto startup type? The delayed-auto startup type is intended to speed up the computer start by delaying the non-essential services.

See What does “delayed start” do in startup type for a Windows service?


To set dependencies between services, use depend= option.

sc.exe create Example start= delayed-auto binPath= "..." depend= service1/service2/service3

If you still want to use delayed-auto on Windows Vista and newer (what is recommended), just create two [Run] entries, one for Windows XP and one for Windows Vista (Windows version 6.0) and newer.

; Delayed automatic start on Vista and newer
Filename: {sys}\sc.exe; Check: IsAdminLoggedOn; \
    Parameters: "create Example start= delayed-auto binPath= ""{app}\Example.exe"" depend= service1/service2/service3"; \
    Flags: runhidden; MinVersion: 6.0

; Automatic start on XP
Filename: {sys}\sc.exe; Check: IsAdminLoggedOn; \
    Parameters: "create Example start= auto binPath= ""{app}\Example.exe"" depend= service1/service2/service3"; \
    Flags: runhidden; OnlyBelowVersion: 6.0

See also Execute different command in Inno Setup Run section based on Windows version.


A better, though a little more complicated solution, is using a scripted constant. It reduces code duplication.

like image 195
Martin Prikryl Avatar answered Sep 17 '25 02:09

Martin Prikryl