Create Program that can Update Itself (Python)
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.

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 accountSign in
Already have an account? Sign in here.
Sign In Now