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.
Locked
User avatar
ALIENQuake
Posts: 66
Joined: Sun Mar 03, 2013 12:45 pm
Has voted: 1 time

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: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 66
Joined: Sun Mar 03, 2013 12:45 pm
Has voted: 1 time

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 84 times

jvierra
Posts: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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.

Locked