Esempio n. 1
0
        /// <summary>
        /// Creates or opens the specified service.
        /// </summary>
        /// <param name="ServiceName">Name of the service.</param>
        /// <param name="DisplayName">The display name.</param>
        /// <param name="ServiceAccess">The service access.</param>
        /// <param name="ServiceType">Type of the service.</param>
        /// <param name="ServiceStart">The service start.</param>
        /// <param name="ServiceError">The service error.</param>
        /// <param name="File">The file.</param>
        internal static IntPtr CreateOrOpen(string ServiceName, string DisplayName, ServiceAccess ServiceAccess, ServiceType ServiceType, ServiceStart ServiceStart, ServiceError ServiceError, FileInfo File)
        {
            var Handle = Service.Create(ServiceName, DisplayName, ServiceAccess, ServiceType, ServiceStart, ServiceError, File);

            if (Handle == IntPtr.Zero)
            {
                return(Service.Open(ServiceName, ServiceAccess));
            }

            return(Handle);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the specified service.
        /// </summary>
        /// <param name="ServiceName">Name of the service.</param>
        /// <param name="DisplayName">The display name.</param>
        /// <param name="ServiceAccess">The service access.</param>
        /// <param name="ServiceType">Type of the service.</param>
        /// <param name="ServiceStart">The service start.</param>
        /// <param name="ServiceError">The service error.</param>
        /// <param name="File">The file.</param>
        internal static IntPtr Create(string ServiceName, string DisplayName, ServiceAccess ServiceAccess, ServiceType ServiceType, ServiceStart ServiceStart, ServiceError ServiceError, FileInfo File)
        {
            IntPtr ServiceManager = WinApi.OpenSCManager(null, null, (uint)ScmAccess.ScManagerAllAccess);

            if (ServiceManager == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            IntPtr Service = WinApi.CreateService(
                ServiceManager,
                ServiceName,
                DisplayName,
                (uint)ServiceAccess,
                (uint)ServiceType,
                (uint)ServiceStart,
                (uint)ServiceError,
                File.FullName,
                null, null, null, null, null
                );

            WinApi.CloseServiceHandle(ServiceManager);

            if (Service == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            return(Service);
        }