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.
Post Reply
User avatar
Lembasts
Posts: 206
Joined: Thu Mar 15, 2012 9:47 am

Auto update an exe on failed version check

Post by Lembasts » Tue Oct 01, 2019 3:54 pm

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
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

Re: Auto update an exe on failed version check

Post by mxtrinidad » Tue Oct 01, 2019 4:04 pm

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: 206
Joined: Thu Mar 15, 2012 9:47 am

Re: Auto update an exe on failed version check

Post by Lembasts » Tue Oct 01, 2019 4:14 pm

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: 7049
Joined: Tue May 29, 2007 4:43 pm

Re: Auto update an exe on failed version check

Post by Alexander Riedel » Tue Oct 01, 2019 4:45 pm

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.

Post Reply