Beispiel #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)
            {
                // TODO
            }

            return(Handle);
        }
Beispiel #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 = Native.OpenSCManager(null, null, (uint)ScmAccess.ScManagerAllAccess);

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

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

            Native.CloseServiceHandle(ServiceManager);

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

            // Native.CloseServiceHandle(Service);

            return(Service);
        }