0

I'm developing a software for my company and it needs to update itself (it's own .exe) upon a certain event happening (the event is irrelevant to this question). The problem I'm encountering is, since this app needs to update it's own .exe, it needs write access to it's own Program Files folder, and I need to figure out a way (that's easily repeatable by the clients) to give it access. Can that be done through the C# code itself? I'm sure there are answers to this question somewhere in this forum but I can't figure out the right search terms to find them.

  • 1
    Applications are not entities of their own in Windows; they only ever execute on behalf of the user. This means you can give a *user* or *group* running your application permission to write, but typically, a user running the application would not have permission to grant themselves write permission on a folder that's not writable yet, so that's not an attractive strategy. You would typically need to elevate to admin to do it, and at that point you may as well use a dedicated update service/scheduled task. – Jeroen Mostert Jun 13 '22 at 18:26
  • Related : [How to automatically update an application?](https://stackoverflow.com/questions/12787761/how-to-automatically-update-an-application-without-clickonce) – Drag and Drop Jun 14 '22 at 07:44

1 Answers1

1

You can't modify an .exe while it's running. You need two programs, one to update and one to do the work. The other requirement is admin access to modify a file if it's located in the Program Files folder.

Spell
  • 384
  • 4
  • 11