public static string[] ApiLwSmEnumerateServices()
        {
            string[] ServicesEnum = null;
            try
            {
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmEnumerateServices()", Logger.ServiceManagerLoglevel);

                int iRet = ServiceManagerInterop.LwSmEnumerateServices(out ServicesEnum);
                if (iRet != 0)
                {
                    Logger.Log("ServiceManagerInteropWrapper:ApiLwSmEnumerateServices returns" + iRet.ToString(), Logger.ServiceManagerLoglevel);
                    return(null);
                }
                //if (ppArry != null && ppArry.Length != 0)
                //{
                //    int idx = 0;
                //    ServicesEnum = new string[ppArry.Length];
                //    foreach (IntPtr pService in ppArry)
                //    {
                //        Console.WriteLine(Marshal.PtrToStringAnsi(pService));
                //        ServicesEnum[idx] = Marshal.PtrToStringAnsi(pService);
                //    }
                //}
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmEnumerateServices is success", Logger.ServiceManagerLoglevel);
            }
            catch (Exception ex)
            {
                Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmEnumerateServices", ex);
            }

            return(ServicesEnum);
        }
        public static ServiceManagerApi.LW_SERVICE_INFO ApiLwSmQueryServiceInfo(IntPtr phServiceHandle)
        {
            ServiceManagerApi.LW_SERVICE_INFO serviceInfo = new ServiceManagerApi.LW_SERVICE_INFO();
            IntPtr serviceInfoPtr = IntPtr.Zero;

            try
            {
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo()", Logger.ServiceManagerLoglevel);

                int iRet = ServiceManagerInterop.LwSmQueryServiceInfo(phServiceHandle, out serviceInfoPtr);
                if (iRet != 0)
                {
                    Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo returns" + iRet.ToString(), Logger.ServiceManagerLoglevel);
                    return(serviceInfo);
                }
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo is success", Logger.ServiceManagerLoglevel);

                serviceInfo = ServiceManagerInterop.UnmarshalServiceInfo(serviceInfoPtr);
            }
            catch (Exception ex)
            {
                Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmQueryServiceInfo", ex);
            }

            return(serviceInfo);
        }
Ejemplo n.º 3
0
        public static ServiceManagerApi.LW_SERVICE_INFO UnmarshalServiceInfo(IntPtr pNativeData)
        {
            _LW_SERVICE_INFO _info = (_LW_SERVICE_INFO)Marshal.PtrToStructure(pNativeData, typeof(_LW_SERVICE_INFO));

            ServiceManagerApi.LW_SERVICE_INFO info = new ServiceManagerApi.LW_SERVICE_INFO();

            info.type              = _info.type;
            info.pwszName          = _info.pwszName;
            info.pwszPath          = _info.pwszPath;
            info.pwszDescription   = _info.pwszDescription;
            info.bAutostart        = _info.bAutostart;
            info.ppwszArgs         = ServiceManagerInterop.UnmarshalStringList(_info.ppwszArgs);
            info.ppwszDependencies = ServiceManagerInterop.UnmarshalStringList(_info.ppwszDependencies);

            return(info);
        }
Ejemplo n.º 4
0
        public static IntPtr MarshalServiceInfo(object ManagedObj)
        {
            ServiceManagerApi.LW_SERVICE_INFO info = (ServiceManagerApi.LW_SERVICE_INFO)ManagedObj;
            _LW_SERVICE_INFO _info   = new _LW_SERVICE_INFO();
            IntPtr           infoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_LW_SERVICE_INFO)));

            _info.pwszName          = info.pwszName;
            _info.pwszPath          = info.pwszPath;
            _info.pwszDescription   = info.pwszDescription;
            _info.bAutostart        = info.bAutostart;
            _info.ppwszArgs         = ServiceManagerInterop.MarshalStringList(info.ppwszArgs);
            _info.ppwszDependencies = ServiceManagerInterop.MarshalStringList(info.ppwszDependencies);

            Marshal.StructureToPtr(_info, infoPtr, false);

            return(infoPtr);
        }
        public static int ApiLwSmReleaseServiceHandle(IntPtr phServiceHandle)
        {
            int iRet = -1;

            try
            {
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmSrvReleaseHandle()", Logger.ServiceManagerLoglevel);

                iRet = ServiceManagerInterop.LwSmReleaseServiceHandle(phServiceHandle);
                if (iRet != 0)
                {
                    Logger.Log("ServiceManagerInteropWrapper:ApiLwSmSrvReleaseHandle returns" + iRet.ToString(), Logger.ServiceManagerLoglevel);
                    return(iRet);
                }
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmReleaseServiceHandle is success", Logger.ServiceManagerLoglevel);
            }
            catch (Exception ex)
            {
                Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmReleaseServiceHandle", ex);
            }
            return(iRet);
        }
        public static IntPtr ApiLwSmAcquireServiceHandle(string sServiceName)
        {
            IntPtr phServiceHandle = IntPtr.Zero;

            try
            {
                Logger.Log(string.Format("ServiceManagerInteropWrapper:ApiLwSmAcquireServiceHandle(Servicename = {0})", sServiceName), Logger.ServiceManagerLoglevel);

                int iRet = ServiceManagerInterop.LwSmAcquireServiceHandle(sServiceName, out phServiceHandle);
                if (iRet != 0)
                {
                    Logger.Log("ServiceManagerInteropWrapper:ApiLwSmAcquireServiceHandle returns" + iRet.ToString(), Logger.ServiceManagerLoglevel);
                    return(IntPtr.Zero);
                }
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmAcquireServiceHandle is success", Logger.ServiceManagerLoglevel);
            }
            catch (Exception ex)
            {
                Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmAcquireServiceHandle", ex);
            }
            return(phServiceHandle);
        }
        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 ApiLwSmQueryServiceReverseDependencyClosure(IntPtr phServiceHandle, out string[] serviceDependencies)
        {
            serviceDependencies = null;
            int iRet = 0;

            try
            {
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceReverseDependencyClosure()", Logger.ServiceManagerLoglevel);

                iRet = ServiceManagerInterop.LwSmQueryServiceReverseDependencyClosure(phServiceHandle, out serviceDependencies);
                if (iRet != 0)
                {
                    serviceDependencies = null;
                    Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceReverseDependencyClosure returns" + iRet.ToString(), Logger.ServiceManagerLoglevel);
                }
                Logger.Log("ServiceManagerInteropWrapper:ApiLwSmQueryServiceReverseDependencyClosure is success", Logger.ServiceManagerLoglevel);
            }
            catch (Exception ex)
            {
                Logger.LogException("ServiceManagerInteropWrapper:ApiLwSmQueryServiceReverseDependencyClosure", ex);
            }

            return(iRet);
        }
Ejemplo n.º 9
0
 object ICustomMarshaler.MarshalNativeToManaged(IntPtr pNativeData)
 {
     return(ServiceManagerInterop.UnmarshalServiceInfo(pNativeData));
 }
Ejemplo n.º 10
0
 IntPtr ICustomMarshaler.MarshalManagedToNative(object ManagedObj)
 {
     return(ServiceManagerInterop.MarshalServiceInfo(ManagedObj));
 }
Ejemplo n.º 11
0
 void ICustomMarshaler.CleanUpNativeData(IntPtr pNativeData)
 {
     ServiceManagerInterop.LwSmFreeServiceInfo(pNativeData);
 }
Ejemplo n.º 12
0
 IntPtr ICustomMarshaler.MarshalManagedToNative(object ManagedObj)
 {
     return(ServiceManagerInterop.MarshalStringList((string[])ManagedObj));
 }