Ejemplo n.º 1
0
        private ExecutableResult ExecServiceCommand(string cmdArgs, bool showOutput)
        {
            using (var p = new Process())
            {
                p.StartInfo.FileName = "sc.exe";
                p.StartInfo.Arguments = cmdArgs;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                var result = p.StartWithRedirectedOutputIO(TimeSpan.FromMinutes(2), CancellationToken.None);

                if (showOutput && result.ExitCode != 0)
                {
                    log.Debug("Exit Code: {0}", result.ExitCode);

                    if (!String.IsNullOrWhiteSpace(result.StandardOut))
                    {
                        log.Debug("{0}{1}", Environment.NewLine, result.StandardOut);
                    }
                    if (!String.IsNullOrWhiteSpace(result.StandardError))
                    {
                        log.Debug("{0}{1}", Environment.NewLine, result.StandardError);
                    }
                    if (result.TimedOut)
                    {
                        log.Debug("Timed Out: {0}", result.TimedOut);
                    }
                }

                return result;
            }
        }