Auto update an exe on failed version check

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 4 years and 6 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
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Auto update an exe on failed version check

Post by Lembasts »

Hi,
Let's say I have a compiled PS exe stored on the user's C drive.
When they launch the exe, it first does a version check.
What I would like to do is automatically copy a newer version from a UNC path to replace the local exe if the version check fails.
However if I do the version check, I cannot automatically do a copy command if the version check fails because the exe is in use.
What's the best way to spawn a task that does the copy successfully please?
Thanks
David
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Auto update an exe on failed version check

Post by mxtrinidad »

First, the process you're describing won't work. As you mention, the executable is already running.

Now, it may be possible to:
1. Create a background process (if the older version exists) to run outside the executable which could terminate the running process.
2. Then uninstall the executable.
3. And finally, run the installer for the new application.

:)
User avatar
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Auto update an exe on failed version check

Post by Lembasts »

Thanks.
There is no install/uninstall for the app.
Its simply a matter of copying a new exe from a server.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Mon Apr 15, 2024 3:28 pm
Answers: 20
Been upvoted: 37 times

Re: Auto update an exe on failed version check

Post by Alexander Riedel »

Write a cmd file (copyapp.cmd) that copies the app file and starts it again. Execute with CMD /c copyapp.cmd and exit immediately.
You may need some kind of delay in there. Timeout or Start-Sleep if you use PowerShell.
You can of course do the same thing in powershell with a powershell script. Erase the cmd or ps1 one when you app starts and it exists to avoid clutter.
Pretty low tech in a way but it works.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 4 years and 6 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