Ejemplo n.º 1
0
        /// <summary>
        /// Native service installation.
        /// </summary>
        /// <param name="args">Arguments.</param>
        private static void Install0(string[] args)
        {
            // 1. Prepare arguments.
            var binPath = new StringBuilder(FullExeName).Append(" ").Append(IgniteRunner.Svc);

            foreach (var arg in args)
                binPath.Append(" ").Append(arg);

            // 2. Get SC manager.
            var scMgr = OpenServiceControlManager();

            // 3. Create service.
            var svc = NativeMethods.CreateService(
                scMgr,
                SvcName,
                SvcDisplayName,
                983551, // Access constant. 
                0x10,   // Service type SERVICE_WIN32_OWN_PROCESS.
                0x2,    // Start type SERVICE_AUTO_START.
                0x2,    // Error control SERVICE_ERROR_SEVERE.
                binPath.ToString(),
                null,
                IntPtr.Zero,
                null,
                null,   // Use priviliged LocalSystem account.
                null
            );

            if (svc == IntPtr.Zero)
                throw new IgniteException("Failed to create the service.", new Win32Exception());

            // 4. Set description.
            var desc = new ServiceDescription {desc = Marshal.StringToHGlobalUni(SvcDesc)};


            try 
            {
                if (!NativeMethods.ChangeServiceConfig2(svc, 1u, ref desc)) 
                    throw new IgniteException("Failed to set service description.", new Win32Exception());
            }
            finally 
            {
                Marshal.FreeHGlobal(desc.desc);
            }
        }
Ejemplo n.º 2
0
 public static extern bool ChangeServiceConfig2(IntPtr svc,  uint infoLevel, ref ServiceDescription desc);