Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a windows service say XYZ. I could set its properties that is "startup type" and the "recovery".My question is how to get its current settings.
I want to "get" its

1.Startup Type
2.Recovery
2.1 First failure
2.2 Second failure
2.3 Subsequent failure
Posted

1 solution

You can set properties using sc[^].

A simple example would be setting failure option via a command string -
C#
var startInfo = process.StartInfo;
 startInfo.FileName = "sc";
 startInfo.WindowStyle = ProcessWindowStyle.Hidden;

 // tell Windows that the service should restart if it fails
 startInfo.Arguments = string.Format("failure \"{0}\" reset= 0 actions= restart/60000", serviceName);

 process.Start();
 process.WaitForExit();

 exitCode = process.ExitCode;
 
Share this answer
 
Comments
Jithin M Jose 21-Jan-16 1:41am    
My question is how to "Get" the properties.
Abhinav S 21-Jan-16 1:53am    
https://msdn.microsoft.com/en-us/library/ms973811.aspx will help you dyynamicaly configure a service using a config file. Restarting the service will be necessary to apply these config changes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900