示例#1
0
        protected override void ProcessRecord()
        {
            ProcessLauncherBase launcher;

            if (_computers != null && _computers.Length > 0)
            {
                launcher = new RemoteProcessLauncher(this, _computers);
            }
            else
            {
                launcher = new LocalProcessLauncher(this);
            }

            ProcessStartInfo startInfo;

            if (ParameterSetName == ParameterSetScriptBlock)
            {
                startInfo = CreateProcessStartInfoForScriptBlock();
            }
            else
            {
                startInfo = CreateProcessStartInfo();
            }

            if (_environment != null)
            {
                startInfo.EnvironmentVariables.Clear();

                foreach (object key in _environment.Keys)
                {
                    startInfo.EnvironmentVariables[key.ToString()] = _environment[key].ToString();
                }
            }

            startInfo.Verb             = _verb;
            startInfo.UseShellExecute  = !_noShellExecute;
            startInfo.CreateNoWindow   = _createNoWindow;
            startInfo.LoadUserProfile  = _loadUserProfile;
            startInfo.WindowStyle      = _windowStyle;
            startInfo.WorkingDirectory = _workingDir;

            if (_credentials != null)
            {
                startInfo.Domain   = _credentials.GetNetworkCredential().Domain;
                startInfo.UserName = _credentials.GetNetworkCredential().UserName;
                startInfo.Password = _credentials.Password;
            }

            Process[] processes = launcher.Start(startInfo);
            WriteObject(processes, true);
        }
示例#2
0
        protected override void ProcessRecord()
        {
            ProcessLauncherBase launcher;

            if (_computers != null && _computers.Length > 0)
            {
                launcher = new RemoteProcessLauncher(this, _computers);
            }
            else
            {
                launcher = new LocalProcessLauncher(this);
            }

            ProcessStartInfo startInfo;

            if (ParameterSetName == ParameterSetScriptBlock)
            {
                startInfo = CreateProcessStartInfoForScriptBlock();
            }
            else
            {
                startInfo = CreateProcessStartInfo();
            }

            if (_environment != null)
            {
                startInfo.EnvironmentVariables.Clear();

                foreach (object key in _environment.Keys)
                {
                    startInfo.EnvironmentVariables[key.ToString()] = _environment[key].ToString();
                }
            }

            startInfo.Verb = _verb;
            startInfo.UseShellExecute = !_noShellExecute;
            startInfo.CreateNoWindow = _createNoWindow;
            startInfo.LoadUserProfile = _loadUserProfile;
            startInfo.WindowStyle = _windowStyle;
            startInfo.WorkingDirectory = _workingDir;

            if (_credentials != null)
            {
                startInfo.Domain = _credentials.GetNetworkCredential().Domain;
                startInfo.UserName = _credentials.GetNetworkCredential().UserName;
                startInfo.Password = _credentials.Password;
            }

            Process[] processes = launcher.Start(startInfo);
            WriteObject(processes, true);
        }