Skip to content

Creative-Media-Group/myelevate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyElevate: Request root privileges

A fork of https://github.com/barneygale/elevate. MyElevate is a small Python library that re-launches the current process with root/admin privileges using one of the following mechanisms:

  • UAC (Windows)
  • AppleScript (macOS)
  • pkexec, gksudo or kdesudo (Linux)
  • sudo (Linux, macOS)

Usage

To use, call myelevate.myelevate() early in your script. When run as root this function does nothing. When not run as root, this function replaces the current process (Linux, macOS) or creates a new process, waits, and exits (Windows). Consider the following example:

import os
from myelevate import myelevate

def is_root():
    return os.getuid() == 0

print("before ", is_root())
myelevate()
print("after ", is_root())

This prints:

before False
before True
after True

On Windows, the new process's standard streams are not attached to the parent, which is an inherent limitation of UAC. By default the new process runs in a new console window. To suppress this window, use (show_console=False).

On Linux and macOS, graphical prompts are tried before sudo by default. To prevent graphical prompts, use (graphical=False).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages