예제 #1
0
        public static void DeleteService(string serviceName)
        {
            var databaseHandle = ServiceUtil.OpenServiceDatabase();

            try { ServiceUtil.DeleteService(databaseHandle, serviceName); }
            finally { SafeNativeMethods.CloseServiceHandle(databaseHandle); }

            // Not sure why this comes after the deletion, but .NET ServiceInstaller does this, so perhaps there's a good reason
            ServiceUtil.StopService(serviceName);
        }
예제 #2
0
        /// <summary>
        /// Uninstalls all services in this process (i.e. unregisters them from the service manager). The current
        /// state of the services doesn't matter for this method - running services will be stopped first.
        /// </summary>
        public void Uninstall()
        {
            var databaseHandle = ServiceUtil.OpenServiceDatabase();

            try
            {
                foreach (var service in Services)
                {
                    ServiceUtil.DeleteService(databaseHandle, service.ServiceName);
                    ServiceUtil.StopService(service.ServiceName); // Not sure why this comes after the deletion, but .NET ServiceInstaller does this, so perhaps there's a good reason
                }
            }
            finally
            {
                ServiceUtil.CloseServiceDatabase(databaseHandle);
            }
        }