EXE Form - overwrite itself

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ALIENQuake
Posts: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

EXE Form - overwrite itself

Post by ALIENQuake »

Hello,

I have prepared very simple autoupdate concept:
1. Read remote json file, check value of the version key, compare it with FileVersionInfo from exe file
2. If they don't match, download executable and overwrite itself

But dealing with this when script is packaged as exe is major pain: the exe file is blocked from overwrite itself because the process is using it. If I close process, I won't able to execute "copy&overwrite".

If this would be c#, I would use Squierl.Windows or something similar but it's Powershell so I can't. Any way to achieve such simple autoupdate concept?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: EXE Form - overwrite itself

Post by jvierra »

Simple. Download file to new location. Schedule a job to copy the new file over old file and exit. Job can restart the EXE with new file after copy.

Note that PSS uses a separate executable to do this which is also easy. If a new file is detected start the second exe and exit current version. The "installer" EXE will then copy the file and restart it.
User avatar
ALIENQuake
Posts: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

Re: EXE Form - overwrite itself

Post by ALIENQuake »

Sorry for late reply, great idea. I've created very simple AutoUpdate application for everyone to use. Everything should be easy to figurue out:
AutoUpdate.zip
(56.04 KiB) Downloaded 188 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: EXE Form - overwrite itself

Post by jvierra »

Thanks for the update. Glad you came up with a solution. I frequently embed this technique in applications in many languages as it is simple and clean.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked