-2

I'm wondering in which cases an application should require to be executed as administrator. Are there specific actions that should require this privilege level?

As an example... My application (C:\Program Files\MyAppFolder\MyApp.exe) must be able to save, copy, move, modify and delete files that are all inside the application folder (C:\Program Files\MyAppFolder). In order to accomplish these actions without problems, should my application require to be run as administrator?

Hwau
  • 850
  • 3
  • 12
  • 23
  • See [What precisely does 'Run as administrator' do?](http://stackoverflow.com/questions/8986971/what-precisely-does-run-as-administrator-do) for what it does, then check if your application needs this. – Jongware May 23 '15 at 12:06
  • This question is better suited for [SuperUser](http://superuser.com) – serk May 23 '15 at 16:44
  • @Jongware: It has been helpful, but I still can't find an answer to my question. – Hwau May 23 '15 at 16:45

1 Answers1

2

You will need to have administrative right to modify/create/delete any file in the folders where operating system is installed. eg. windows, Program Files, appdata etc. Following actions requires pemission:

  • To change any system settings
  • To install/uninstall any program
  • To make any registry changes(Registry Editing)

If you are tring to develop this might help.

Community
  • 1
  • 1
DarKnight
  • 83
  • 10
  • And what if my application must be able to save, copy, move, modify and delete files that are inside the application folder? (C:\Program Files\MyAppFolder\). These actions require administrator privileges? And what happens if application try to do this without administrator privileges? – Hwau May 23 '15 at 16:34
  • You must have admin privileges to make changes to files in system folders, which includes anything inside of `C:\Program Files`. If you don't, your file operations will fail with `ERROR_ACCESS_DENIED` or `ERROR_ELEVATION_REQUIRED` errors. – Remy Lebeau May 23 '15 at 16:46
  • @RemyLebeau: Due to this fact, users that can't have administrator privileges shouldn't run my application? (Assuming my application must do this things). Or is there some trick? – Hwau May 23 '15 at 16:51
  • Furthermore, what do you mean for "system folders"? – Hwau May 23 '15 at 16:54
  • 1
    @Hwau: no, it simply means you need to design your app with proper security in mind. For starters, why are you creating/manipulating files in your application folder to begin with? They don't belong there. [Where Should I Store my Data and Configuration Files if I Target Multiple OS Versions?](http://blogs.msdn.com/b/patricka/archive/2010/03/18/where-should-i-store-my-data-and-configuration-files-if-i-target-multiple-os-versions.aspx). – Remy Lebeau May 23 '15 at 17:17
  • @Hwau: If you must run your app without admin privileges, but gain admin privileges when you need to do something, you have to either 1) impersonate an admin user when needed, 2) move your admin tasks to a separate process that runs elevated, or 3) move your admin tasks to a COM object that you can instantiate using the COM Elevation Moniker. – Remy Lebeau May 23 '15 at 17:20
  • @Hwau: "system folder" refers to any folder that is owned/managed by the operating system, especially in regards to security access. `Program Files` is such a folder. – Remy Lebeau May 23 '15 at 17:21
  • @RemyLebeau: My application updates itself, so it must be able to delete, move and copy files. I read the article and it's very interesting, but I still can't understand which is the right folder for application files (no documents, no configurations, and are shared between all users). In cases like this, which solution would you suggest to adopt? – Hwau May 24 '15 at 08:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78621/discussion-between-remy-lebeau-and-hwau). – Remy Lebeau May 24 '15 at 08:38