Example #1
0
        /// <summary>
        /// Executes the progam.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Debugging.PrintDebugBuild();

            /* In this array, the first item (at 0) will be the path to the current
             * executable. The second item (at 1) will be the executable to be
             * invoked. Further arguments are input to the other process.
             */
            string[] commandLineArgs = Environment.GetCommandLineArgs();

            if (RuntimeChecks.CheckHelp(commandLineArgs))
            {
                return;
            }
            if (RuntimeChecks.CheckAliases(commandLineArgs))
            {
                return;
            }

            ProcessStartInfo processStartInfo;

            if (commandLineArgs.Length < 2)
            {
                processStartInfo = new ProcessStartInfo(Settings.GetDefaultExecutable())
                {
                    UseShellExecute = true,
                    Verb            = "runas"
                };
            }
            else if (commandLineArgs[1] == "-c" || commandLineArgs[1] == "-C")
            {
                bool leaveOpen = commandLineArgs[1] == "-C";

                CommandEscaper       commandEscaper   = new CommandEscaper();
                IEnumerable <string> escapedArguments = commandLineArgs.Skip(2).Select(a => commandEscaper.Escape(a));
                string passedArguments = string.Join(" ", escapedArguments);

                processStartInfo = new ProcessStartInfo("cmd", $"/{(leaveOpen ? "K" : "C")} {passedArguments}")
                {
                    UseShellExecute = true,
                    Verb            = "runas"
                };
            }
            else
            {
                string executable = commandLineArgs[1];

                CommandEscaper       commandEscaper   = new CommandEscaper();
                IEnumerable <string> escapedArguments = commandLineArgs.Skip(2).Select(a => commandEscaper.Escape(a));
                string arguments = string.Join(" ", escapedArguments);

                processStartInfo = new ProcessStartInfo(executable, arguments)
                {
                    UseShellExecute = true,
                    Verb            = "runas"
                };
            }

            ProcessUtilities.RunSafe(processStartInfo, false);
        }
Example #2
0
        /// <summary>
        /// Executes the progam.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Debugging.PrintDebugBuild();

            /* In this array, the first item (at 0) will be the path to the current
             * executable. The second item (at 1) will be the executable to be
             * invoked. Further arguments are input to the other process.
             */
            string[] commandLineArgs = Environment.GetCommandLineArgs();

            if (RuntimeChecks.CheckHelp(commandLineArgs))
            {
                Exit();
            }
            if (RuntimeChecks.CheckAliases(commandLineArgs))
            {
                return;
            }

            ProcessStartInfo processStartInfo = CreateProcessStartInfo(commandLineArgs);

            if (processStartInfo == null)
            {
                ConsoleUtilities.HighlightConsole(() => Console.WriteLine("Please specify the command to execute."));
                Console.WriteLine();
                Console.WriteLine("Usage: sudo <executable> [<executable arguments>]");
                Exit();
            }

            if (ProcessUtilities.HasOwnWindow())
            {
                Console.Title = $"{ApplicationInfo.Name} - {processStartInfo.FileName} {processStartInfo.Arguments}";
            }
            int?exitCode = ProcessUtilities.RunSafe(processStartInfo, true);

            Exit(exitCode);
        }