1

Im the developer of a Windows software application which I currently release as "portable", meaning the user needs to extract it somewhere into his disk. Along with it I ship a small update tool (external app / python script converted into an .exe through pyinstaller) that handles updates as follows:

  1. Main app calls the update tool in the background and quits
  2. Update tool runs: fetches new files, removes files in the main app directory and extract new ones (the new main app .exe, dlls, and other files that might be required)
  3. Update tool call main app again

Questions: by creating an installer (NSIS / InnoSetup) and letting the user to install the app in Program Files, will I be able to keep this update tool? I mean, can it have enought permissions to do the update like that? If not, how can/should the updates be done?

cidadao
  • 111

1 Answers1

1

It sounds like you just need to have the updater app be able to elevate privileges. I found the following gist here: https://gist.github.com/GaryLee/d1cf2089c3a515691919

import sys
import ctypes

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


if __name__ == '__main__':
ret = run_as_admin()
if ret is True:
    print 'I have admin privilege.'
    raw_input('Press ENTER to exit.')
elif ret is None:
    print 'I am elevating to admin privilege.'
    raw_input('Press ENTER to exit.')
else:
    print 'Error(ret=%d): cannot elevate privilege.' % (ret, )