[Windows] is renaming own exe while it is running legit?

Just starting out? Need help? Post your questions and find answers here.
novablue
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Nov 27, 2016 6:38 am

[Windows] is renaming own exe while it is running legit?

Post by novablue »

Hi, i recently found out that it is allowed to rename exe and dll files while they are running. Is this a legit feature by windows that allows me to easier update my own program or should i use another way?

Pseudo Code:

Code: Select all

; Program start

; Clean up old file
If FileSize("program.old") > -1 : DeleteFile("program.old") : EndIf

; Apply update
RenameFile(ProgramFilename(), "program.old")
RenameFile("LatestUpdate.exe", ProgramFilename())

; Restart
RunProgram(ProgramFilename())
End
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: [Windows] is renaming own exe while it is running legit?

Post by BarryG »

novablue wrote: Tue Mar 29, 2022 1:45 ami recently found out that it is allowed to rename exe and dll files while they are running
I just tried this with some non-PureBasic running executables and you're right! Never seen that being permitted before.
novablue
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Nov 27, 2016 6:38 am

Re: [Windows] is renaming own exe while it is running legit?

Post by novablue »

So far i have tested this on Windows 7 x64 and Windows 10 x64 and it is working. I am really wondering if this is a feature by MS to allow easier updating. If it is not just some odd glitch then it would make things so much easier.
novablue
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Nov 27, 2016 6:38 am

Re: [Windows] is renaming own exe while it is running legit?

Post by novablue »

According to This it was also possible in 2000/XP but i have yet to find an official documentation about this.
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: [Windows] is renaming own exe while it is running legit?

Post by BarryG »

It definitely wasn't possible in the past, because it's something I tried a lot in the older days.

So I just tested it with "Quake2.exe" (the game). I renamed this to "Q2.exe" while it was running, and then I quit the game. Double-clicking "Q2.exe" then failed to start the game, until I renamed it back to "Quake2.exe" again. Something to be aware of.
Post Reply