views:

465

answers:

1

Scenario:

A WCF service running as a Windows Service. Account is "User".


What is done:

I have overridden the OnBeforeInstall in the projectinstaller to be able to set username and password from a config file.


What I would be able to do:

I'd like to be able to set the starttype as Automatic (Delayed Start)


What I have tried:

I put the following coderow in the overridden OnBeforeInstall

serviceInstaller1.StartType = ServiceStartMode.Automatic + 1;

Figured I would trick the ServiceStartMode enum into representing Automatic (Delayed Start), didn't work. Haven't tried anything more simply because I couldn't find anything to try.


What I have found on the net:

I found out that Automatic (Delayed Start) will be available in .NET 4, but that doesn't help me right now. MSDN I found out that DelayedAutoStart could be added to the service's configuration key, but this feels like a hack if I should do this from code. But maybe this is the only solution available for me at this point?

blogs.technet.com/askperf/archive/2008/02/02/ws2008-startup-processes-and-delayed-automatic-start.aspx (add "http://" at the beginning, was not able to post 2 hyperlinks)

Any ideas?

Robert Persson, Sweden

A: 

Your only other option is to use P/invoke to call ChangeServiceConfig2 with SERVICE_CONFIG_DELAYED_AUTO_START_INFO. But since you seem to be unwilling to add the registry entry, I doubt you would want to use P/invoke. There's no other way to do it from the .NET Framework (< 4.0).

wj32
Thanks!The contractor wanted the service to have Automatic (Start Delayed) if it was possible, but it wasn't crucial. So we'll wait until .NET 4.Thanks for the answer.
Robert Persson