Jump to content

Create Program that can Update Itself (Python)

JoeTheSmiter
Go to solution Solved by Master Disaster,
17 minutes ago, JoeTheSmiter said:

Noob question. I'm currently working in Python and have created the exe using Pyinstaller. My program currently installs and updates itself by using Inno Setup, but every time the program updates the installation wizard has to run to be able to write to C:/Program Files. How do you update a program without having to us an installer and ask for administrator rights every time?
My program currently checks for updates then downloads the installer and runs that, but I'd much rather have it just download a zip and replace only the necessary files without needing to prompt the user.

This might be helpful...

     # Self-elevate the script if required
    if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
     if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
      $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
      Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
      Exit
     }
    }

Place it at the beginning on a powershell script and it will cause the script to self elevate.

 

Have your app pull the files and run a PS script then have the elevated script copy the files into Program Files.

Noob question. I'm currently working in Python and have created the exe using Pyinstaller. My program currently installs and updates itself by using Inno Setup, but every time the program updates the installation wizard has to run to be able to write to C:/Program Files. How do you update a program without having to us an installer and ask for administrator rights every time?
My program currently checks for updates then downloads the installer and runs that, but I'd much rather have it just download a zip and replace only the necessary files without needing to prompt the user.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, JoeTheSmiter said:

How do you update a program without having to us an installer and ask for administrator rights every time? ...replace only the necessary files without needing to prompt the user.

 

giphy.gif.6ec51fe05bab42feb64453554e8bc7da.gif

VGhlIHF1aWV0ZXIgeW91IGJlY29tZSwgdGhlIG1vcmUgeW91IGFyZSBhYmxlIHRvIGhlYXIu

^ not a crypto wallet

Link to comment
Share on other sites

Link to post
Share on other sites

Why not just have it install to the user directory instead of program files? I don't think admin rights would be needed for a single-user install.

Link to comment
Share on other sites

Link to post
Share on other sites

If your application is installed in Program Files or some other folder which requires administrative rights to install or run from, then the application updating the files (copying files and overwriting existing files) also needs administrative rights.

The easiest would be to have a separate update application which can be launched, then download the latest information about your software (ex version, release date) and if there's something new, the updater can download the zip from a remote server, unpack it into a temporary folder, then overwrite existing application files as needed.  Also, the updater can monitor if instances of your application are opened and ask user to close the application in order to update it, ask for administrative rights if needed and so on.

Link to comment
Share on other sites

Link to post
Share on other sites

17 minutes ago, JoeTheSmiter said:

Noob question. I'm currently working in Python and have created the exe using Pyinstaller. My program currently installs and updates itself by using Inno Setup, but every time the program updates the installation wizard has to run to be able to write to C:/Program Files. How do you update a program without having to us an installer and ask for administrator rights every time?
My program currently checks for updates then downloads the installer and runs that, but I'd much rather have it just download a zip and replace only the necessary files without needing to prompt the user.

This might be helpful...

     # Self-elevate the script if required
    if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
     if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
      $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
      Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
      Exit
     }
    }

Place it at the beginning on a powershell script and it will cause the script to self elevate.

 

Have your app pull the files and run a PS script then have the elevated script copy the files into Program Files.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

You can try using a zero day exploit and hack the system I guess. Any other ideas?

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×