public static ServiceManagerApi.LW_SERVICE_STATUS ApiLwSmQueryServiceStatus(IntPtr phServiceHandle) { ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = new ServiceManagerApi.LW_SERVICE_STATUS(); try { Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus()", Logger.ServiceManagerLoglevel); int iRet = ServiceManagerInterop.LwSmQueryServiceStatus(phServiceHandle, out serviceStatus); if (iRet != 0) { Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus returns" + iRet.ToString(), Logger.ServiceManagerLoglevel); return(serviceStatus); } Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus is success", Logger.ServiceManagerLoglevel); } catch (Exception ex) { Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo", ex); } return(serviceStatus); }
public static int StartAllServiceDependencies(IntPtr pHandle, ref int iReturn) { try { if (pHandle != IntPtr.Zero) { ServiceManagerApi.LW_SERVICE_INFO serviceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pHandle); ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = ServiceManagerInteropWrapper.ApiLwSmQueryServiceStatus(pHandle); if (serviceStatus.state == ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING) { Logger.Log("Dependency servcie: " + serviceInfo.pwszName + " running"); return(iReturn); } if (serviceInfo.ppwszDependencies != null && serviceInfo.ppwszDependencies.Length != 0) { foreach (string service in serviceInfo.ppwszDependencies) { Logger.Log("Dependency servcie: " + service); IntPtr pDHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(service); if (pDHandle != IntPtr.Zero) { ServiceManagerApi.LW_SERVICE_INFO InnerServiceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pDHandle); ServiceManagerApi.LW_SERVICE_STATUS Status = ServiceManagerInteropWrapper.ApiLwSmQueryServiceStatus(pDHandle); if (InnerServiceInfo.ppwszDependencies == null || InnerServiceInfo.ppwszDependencies.Length == 0) { if (Status.state != ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING) { iReturn = ServiceManagerInteropWrapper.ApiLwSmStartService(pDHandle); if (iReturn != 0) { return(iReturn); } } else { Logger.Log("Dependency servcie: " + service + " running"); } } else { StartAllServiceDependencies(pDHandle, ref iReturn); iReturn = ServiceManagerInteropWrapper.ApiLwSmStartService(pDHandle); } ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pDHandle); } } iReturn = ServiceManagerInteropWrapper.ApiLwSmStartService(pHandle); } else { if (serviceStatus.state != ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING) { iReturn = ServiceManagerInteropWrapper.ApiLwSmStartService(pHandle); } } } } catch (Exception ex) { Logger.LogException("ServiceManagerInteropWrapper:StartAllServiceDependencies", ex); } return(iReturn); }
public static extern int LwSmQueryServiceStatus(IntPtr phHandle, out ServiceManagerApi.LW_SERVICE_STATUS pStatus);
public static ServiceManagerApi.LW_SERVICE_STATUS ApiLwSmQueryServiceStatus(IntPtr phServiceHandle) { ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = new ServiceManagerApi.LW_SERVICE_STATUS(); try { Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus()", Logger.ServiceManagerLoglevel); int iRet = ServiceManagerInterop.LwSmQueryServiceStatus(phServiceHandle, out serviceStatus); if (iRet != 0) { Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus returns" + iRet.ToString(), Logger.ServiceManagerLoglevel); return serviceStatus; } Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceStatus is success", Logger.ServiceManagerLoglevel); } catch (Exception ex) { Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo", ex); } return serviceStatus; }