Python Forum
How a Mac OS software can restart itself with admin permission in Python 3.7?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How a Mac OS software can restart itself with admin permission in Python 3.7?
#1
**Environment**

Python 3.7

Mac OS Catalina 10.15

**Problem**


I am developing a software in python. I would like to distribute it as commercial software.

I am compiling it with Nuitka for Windows and PyInstaller for Mac (because Nuitka can't do the job on Mac).

My software need to install some libraries and other stuff like JDK, SDK tools, etc...
It needs also to change some environment variables. This can be done only with admin permissions.

So the first thing my software does is to **check if it is running with admin permissions or not. If it is not the case it restart itself with admin permissions.**

I succeeded to do it for Windows, but I have issues for Mac.

Here is the code:

def is_admin():
        try:
            is_admin = os.getuid() == 0
    
        except AttributeError:
            is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
        return is_admin
    
    
    def StartMyAppasAdmin():
        if not is_admin():
            if platform.system() == 'Windows':
                ctypes.windll.shell32.ShellExecuteW(None, "runas", 'hello.exe', '', None, 1)
                sys.exit()
            elif platform.system() == 'Darwin':
                subprocess.call(["sudo","/usr/bin/open", os.path.join(os.path.dirname(sys.argv[0]),"hello")])
                sys.exit()
    
    if __name__ == "__main__":
        StartMyAppasAdmin()
In Windows, it works fine.

In Mac OS, the app can't be launch. And if I open the executable from terminal, it ask for admin password, then it restart and ask again for admin password, then it restart, etc... in a loop.

Someone knows what I am doing wrong?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  KivyMD android app - problem with permission polak7gt 0 247 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 643 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 954 Aug-09-2023, 01:24 PM
Last Post: erg
  The INSERT permission was denied on the object Steven5055 2 1,417 Feb-25-2023, 11:37 PM
Last Post: Steven5055
  Is there software/tool for coding Python? dee 11 2,747 Jun-14-2022, 02:32 PM
Last Post: dee
  Permission issue when using scapy jao 3 9,449 Feb-05-2022, 06:14 PM
Last Post: snippsat
  [split] Could you please clarify where i did mistake also how run without admin right Abubakkar 1 1,753 Jun-14-2021, 09:32 AM
Last Post: Larz60+
  Error no 13: Permission denied in python shantanu97 1 6,095 Mar-31-2021, 02:15 PM
Last Post: snippsat
  Using python to execute app or cmd that requires admin credentials thewolf 0 2,078 Mar-05-2021, 08:15 PM
Last Post: thewolf
  Problem: Restart kernel onPydev console when trying to install a python package poppy2020 1 7,558 Nov-25-2020, 06:13 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020