/// <summary>
    /// Checks that MSMQ is installed, configured correctly, and started, and if not takes the necessary corrective actions to make it so.
    /// </summary>
    public bool StartMsmqIfNecessary()
    {
        var processUtil = new ProcessUtil(Host);

        if (!InstallMsmqIfNecessary())
        {
            return false;
        }

        try
        {
            using (var controller = new ServiceController("MSMQ"))
            {
                if (IsStopped(controller))
                {
                    processUtil.ChangeServiceStatus(controller, ServiceControllerStatus.Running, controller.Start);
                }
            }
        }
        catch (InvalidOperationException)
        {
            WriteWarning("MSMQ windows service not found! You may need to reboot after MSMQ has been installed.");
            return false;
        }

        return true;
    }
예제 #2
0
 protected override void BeginProcessing()
 {
     var processUtil = new ProcessUtil(Host);
     if (!processUtil.IsRunningWithElevatedPrivileges())
     {
         var exception = new SecurityException("This command requires elevated privileges");
         ThrowTerminatingError(new ErrorRecord(exception, null, ErrorCategory.PermissionDenied, null));
     }
 }
예제 #3
0
        /// <summary>
        ///     Checks that the MSDTC service is running and configured correctly, and if not
        ///     takes the necessary corrective actions to make it so.
        /// </summary>
        public void StartDtcIfNecessary()
        {
            var processUtil = new ProcessUtil(Host);

            if (DoesSecurityConfigurationRequireRestart(true))
            {
                processUtil.ChangeServiceStatus(Controller, ServiceControllerStatus.Stopped, Controller.Stop);
            }

            processUtil.ChangeServiceStatus(Controller, ServiceControllerStatus.Running, Controller.Start);
        }