问题
I have a package which runs uses Gtk and written in vala.A dialog box or a gui opens after selecting a file.I want this dialog box or gui to run as root so as to open and read the files which don't open with normal users.I have this code
static void open_file(string filename) {
selected_file = filename;
stdout.printf(selected_file);
new ProgressWindow(selected_file, {});
}
I want to run ProgressWindow
to run as root.Is it possible?
回答1:
No. To run as root, it must be in a separate process and you must run that process using pkexec
via PolicyKit. Here's a tutorial on PolicyKit in Vala.
来源:https://stackoverflow.com/questions/42779843/run-part-of-code-as-root