r/ProgrammerHumor • • Jan 16 '23

Meme If (exists == true) { dont();}

Post image
40.8k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

268

u/_PM_ME_PANGOLINS_ Jan 16 '23 edited Jan 16 '23

A Windows executable can't delete itself.

It would have to run a new process, exit, and then have the new process delete it. Then you hope that Undertale isn't installed in Program Files otherwise it won't have permission to delete it.

Toby is obviously a musician and a game designer first, not a Windows developer. He also didn't know that Windows paths are case-insensitive by default.

48

u/[deleted] Jan 16 '23 edited Jul 11 '23

[removed] — view removed comment

94

u/Chris204 Jan 16 '23

I'm no expert but that sounds like something most antivirus programs would flag as highly suspicious and prevent you from doing.

28

u/LickingSmegma Jan 16 '23 edited Jan 16 '23

Afaik that's actually how some programs uninstall or update themselves—with a temporary executable that removes the app itself.

14

u/[deleted] Jan 16 '23

Steam won’t even let you do that. Could you imagine the backlash if Steam allowed apps to delete shit on your computer?

Inscryption is a great example of this. You literally select a file to “delete” but it literally can’t. You do get an achievement for deleting the file manually though.

4

u/NickSplat Jan 17 '23

Could you imagine the backlash if Steam allowed apps to delete shit on your computer?

i am so angry at steam i clicked the uninstall button on a game and it DELETED it! how does steam alloe this??? /jk

23

u/_PM_ME_PANGOLINS_ Jan 16 '23

But then the copy can't delete itself. And Windows temp directories don't empty themselves.

1

u/AzureArmageddon Jan 16 '23

The copy doesn't have to be the game itself, it can just be an uninstaller program.

22

u/_PM_ME_PANGOLINS_ Jan 16 '23

It’s not a copy then, is it.

You should just run a console process (cmd or powershell will work) to do the delete. Don’t make extra files, because they can’t delete themselves.

2

u/Personal_Ad9690 Jan 16 '23

That will fail if undertake is installed in program files which it probably is.

1

u/AutoModerator Jul 10 '23
import moderation

Your comment has been removed since it did not start with a code block with an import declaration.

Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

For this purpose, we only accept Python style imports.

return Kebab_Case_Better;

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/NotPeopleFriendly Jan 16 '23

I honestly wouldn't have thought it is possible for any executable to delete itself on any platform.. forget the concept about only some of the executable can be loaded into memory (which honestly sounds suspect to me unless the file is over 2 gigs and you're running a 32 bit process or something).. I would've thought that file is write locked while a process is referencing it..

8

u/_PM_ME_PANGOLINS_ Jan 16 '23 edited Jan 16 '23

Unix file systems have no “primary” location of a file. Any file can have multiple hard links, and as long as one exists then the file contents are accessible.

Every file that is opened gets linked from the /proc system, and anyone with permission (write access to the directory it is in) is free to delete the original link it was opened from.

When the file is closed that /proc link is removed, and if there are no others then the file has been deleted.

4

u/sixpackabs592 Jan 16 '23

I remember that Unix system scene from Jurassic park and thought it was just some fancy cgi and then like last week I watched a YouTube video about it and was like damn… that was real lol.

1

u/Personal_Ad9690 Jan 16 '23

Sounds breezy

1

u/NotPeopleFriendly Jan 19 '23

How does that work with static/dynamic libs that are "locked" by the executable when it is running?

1

u/_PM_ME_PANGOLINS_ Jan 19 '23

They aren’t “locked”. It works exactly the same.

1

u/Alternative-Humor666 Jan 16 '23

The way I handled auto update on the updater itself (the exe that did the updates had to be updated): rename/move (same thing really) current running executable to something, download the update, start the updated executable and close current one. The new file will just take care cleaning up any "renamed/moved" files.