コード例 #1
0
        public override bool RestartAsRoot()
        {
            string        path         = Platform.Instance.GetExecutablePath();
            List <string> args         = CommandLine.SystemEnvironment.GetFullArray();
            string        defaultsPath = Core.Platform.Instance.LocateExecutable("defaults");

            if (defaultsPath != "")
            {
                // If 'white', return error in StdErr and empty in StdOut.
                SystemShell s = new SystemShell();
                s.Path = defaultsPath;
                s.Arguments.Add("read");
                s.Arguments.Add("-g");
                s.Arguments.Add("AppleInterfaceStyle");
                s.Run();
                string colorMode = s.StdOut.Trim().ToLowerInvariant();
                if (colorMode == "dark")
                {
                    args.Add("gui.osx.style=\"dark\"");
                }
            }

            RootLauncher.LaunchExternalTool(path, args.ToArray());
            return(true);
        }
コード例 #2
0
ファイル: Platform.cs プロジェクト: DreamAuth/Eddie
        public override int StartProcessAsRoot(string path, string[] arguments, bool consoleMode)
        {
            bool canRunAsRoot = Platform.Instance.FileRunAsRoot(path);

            System.Diagnostics.Process processShell = null;
            bool processDirectResult = false;

            if (canRunAsRoot)
            {
                processShell = new System.Diagnostics.Process();
                processShell.StartInfo.FileName  = path;
                processShell.StartInfo.Arguments = string.Join(" ", arguments);
            }
            else
            {
                if (Engine.Instance.ConsoleMode)
                {
                    processShell = new System.Diagnostics.Process();
                    processShell.StartInfo.FileName  = "sudo";
                    processShell.StartInfo.Arguments = "\"" + path + "\" " + string.Join(" ", arguments);
                }
                else
                {
                    // Alternate version via osascript
                    //processShell = new System.Diagnostics.Process();
                    //processShell.StartInfo.FileName = "osascript";
                    //processShell.StartInfo.Arguments = " -e 'do shell script \"" + path + " " + string.Join(" ", arguments) + "\" with prompt \"" + LanguageManager.GetText("HelperPrivilegesPrompt").Safe() + "\" with administrator privileges'";

                    // Alternate version with RootLauncher
                    // TOFIX: pending pid, create launchd don't start it (no root?)
                    // Required for elevated-spot-check-parent-pid
                    processDirectResult = RootLauncher.LaunchExternalTool(path, arguments);
                }
            }

            if (processShell != null)
            {
                processShell.StartInfo.WorkingDirectory = "";
                processShell.StartInfo.Verb             = "run";
                processShell.StartInfo.CreateNoWindow   = true;
                processShell.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
                processShell.StartInfo.UseShellExecute  = false;
                processShell.Start();
                return(processShell.Id);
            }
            else
            {
                return(processDirectResult ? -1 : 0);
            }
        }