예제 #1
0
        /// <summary>
        /// 创建服务
        /// </summary>
        /// <param name="servicesName"></param>
        /// <returns></returns>
        public static string InstallServices(ServiceInfo info)
        {
            IntPtr scmhandle = WindowsAPI.OpenSCManager(null, null, ControlManagerAccessTypes.SC_MANAGER_CREATE_SERVICE);

            if (scmhandle == IntPtr.Zero)
            {
                return("获取信息失败");
            }
            int    lpdwTagId = 0;
            IntPtr schandle  = WindowsAPI.CreateService(scmhandle, info.Name, info.DisplayName,
                                                        ServicesAccessType.SERVICE_ALL_ACCESS, ServiceType.Win32OwnProcess,
                                                        info.StarType, ServicesErrorControl.SERVICE_ERROR_NORMAL,
                                                        info.Path, null, lpdwTagId, null, null, null);

            WindowsAPI.CloseServiceHandle(scmhandle);
            if (schandle == IntPtr.Zero)
            {
                return("创建服务失败");
            }

            WindowsAPI.CloseServiceHandle(schandle);
            RefreashServices();
            return(SetDescription(info));;
        }