Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

c# - How to make Windows Service start as "Automatic (Delayed Start)"

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?

Any ideas?

Robert Persson, Sweden

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Now that .NET 4.0 is here:

serviceInstaller1.StartType = ServiceStartMode.Automatic;
serviceInstaller1.DelayedAutoStart = true;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...