"svandanapu" <sk**************@gmail.comwrote in message
news:85**********************************@w28g2000 hsf.googlegroups.com...
Hi All,
I written one windows service and its working fine. I Need to check
the recovery settings of that service from one windows application.
How do I can get the recovery settings of(first failure, second
failure and third failure) a service programatically. can any one
please help me in this regard.
Thanks in advance
Sivakumar V
There is nothing in the framework that covers this, so you'll have to call
the native QueryServiceConfig2 service API for this.
To give you a head start, herewith a class with the Pinvoke declaration and
the structures required by this function.
class ServiceConfigEx
{
[DllImport("advapi32.dll", CharSet=CharSet.Unicode,
SetLastError=true)]
public static extern int QueryServiceConfig2(IntPtr serviceHandle,
int infoLevel,
IntPtr query_service_config_ptr, int bufferSize, out int
bytesNeeded);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct SERVICE_FAILURE_ACTIONS
{
public uint dwResetPeriod;
public string rebootMsg;
public string command;
public uint numActions;
public IntPtr actions; //ptr to an array of AC_ACTION structures
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct SC_ACTION
{
public SC_ACTION_TYPE type;
public uint delay;
}
public enum SC_ACTION_TYPE
{
SC_ACTION_NONE,
SC_ACTION_RESTART,
SC_ACTION_REBOOT,
SC_ACTION_RUN_COMMAND
}
public const int SERVICE_CONFIG_FAILURE_ACTIONS = 2;
}
Note that this information is only available on Vista and higher, you also
need to administrator privileges to call this API.
Willy.