From 764ed0fdc40b323f215430e70ee710eba5d148c0 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Thu, 10 Sep 2015 12:26:43 -0400 Subject: [PATCH] Added _is_root() Cross-platform way to check admin rights http://stackoverflow.com/questions/1026431/cross-platform-way-to-check-admin-rights-in-a-python-script-under-windows --- bash_kernel/install.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index f123bfc..c0680d2 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -22,6 +22,14 @@ def install_my_kernel_spec(user=True): print('Installing IPython kernel spec') install_kernel_spec(td, 'bash', user=user, replace=True) +def _is_root(): + """Cross-platform way to check admin rights""" + import ctypes, os + try: + return os.geteuid() == 0 + except AttributeError: + return ctypes.windll.shell32.IsUserAnAdmin() != 0 + def main(argv=None): install_my_kernel_spec()