delex
delex

Reputation: 211

python run as administrator interrupt wxpython

I am developing a script that uses admin privilege I use the code beneath to acquire it, but when I add it to my script, suddenly the wxpython won't show.

What should I do to fix it?

    # Enable Adminstrator Privelaged
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
    script = os.path.abspath(sys.argv[0])
    params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
    try:
        shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
    except Exception as e:
        if e[-1]=="The operation was canceled by the user.":
            print "נא לאפשר הרשאות מנהלן לתוכנה"
        else:
            print "שגיאה בהפעלת המנהלן, פרטי השגיאה:\n"+str(e)
    sys.exit(0)


app = wx.App(False)
x=MainGUI(None,app)
app.MainLoop()

Upvotes: 0

Views: 94

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

If I am reading this code correctly, it looks like you exit your script if the the user doesn't pass in asadmin on the command line. So when you run the script with no parameters or with the wrong string passed in, then your if statement runs. When that runs, it calls sys.exit(0) at the end, which causes the script to end there.

Thus you never reach the wxPython part of the code.

Upvotes: 1

Related Questions