1

i am using python 2.7 and ctypes. I am developing a program that will run on a windows computer with a restricted privileges, and do not have full admin privileges. i searched at google and didn't found how i change the code that it will fit to restricted privileges. the program needs privileges to change the computer IP address. thank you

def run_as_admin(argv=None, debug=False):
shell32 = ctypes.windll.shell32
if argv is None and shell32.IsUserAnAdmin():
    return True

if argv is None:
    argv = sys.argv
if hasattr(sys, '_MEIPASS'):
    # Support pyinstaller wrapped program.
    arguments = map(unicode, argv[1:])
else:
    arguments = map(unicode, argv)
argument_line = u' '.join(arguments)
executable = unicode(sys.executable)
if debug:
    print 'Command line: ', executable, argument_line
ret = shell32.ShellExecuteW(None, u"runas", executable, argument_line, None, 1)
if int(ret) <= 32:
    return False
return None
delex
  • 153
  • 3
  • 13
  • What's the output or error stacktrace? Why do you need to encode every string in unicode? – Adonis Apr 09 '18 at 14:34
  • I've just used Google and I found a stackoverflow question that maybe can help you (I hope): https://stackoverflow.com/questions/19672352/how-to-run-python-script-with-elevated-privilege-on-windows – Sergio La Rosa Apr 09 '18 at 15:25

0 Answers0