Page 1 of 1

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

Posted: Tue Mar 29, 2022 1:45 am
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

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

Posted: Tue Mar 29, 2022 1:55 am
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.

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

Posted: Tue Mar 29, 2022 1:58 am
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.

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

Posted: Tue Mar 29, 2022 2:20 am
by novablue
According to This it was also possible in 2000/XP but i have yet to find an official documentation about this.

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

Posted: Tue Mar 29, 2022 2:47 am
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.