Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to design around Windows UAC limitations?

I found out an application I wrote does not work properly under Windows Vista/7 if UAC is enabled at any level, because it writes files to the install directory of the program, defaults to "C:\Program Files\MyProgram." If UAC is disabled (or on any other version of Windows) it works properly - I read that UAC denies applications write access to the Program Files directory by default.

My question is, well, how should I write my application so that it can be used without any "rights" needed at all. I don't want users to have to run it with elevated privileges or as administrator. I just want it to work. Are there certain directories that any app has write access to under UAC where it might be better to write my files? They are mostly config files that are dynamically created/destroyed/updated.

Thanks for you help!

like image 223
JimDaniel Avatar asked Aug 31 '09 17:08

JimDaniel


2 Answers

Per-user application specific data should be written in the AppData folder.

You should use SHGetKnownFolderPath with FOLDERID_LocalAppData.

In managed code, you should use System.Environment.GetFolderPath with System.Environment.SpecialFolder.LocalApplicationData.

like image 75
Michael Avatar answered Sep 22 '22 09:09

Michael


Yes, there are specific locations. Consider this msdn article as a first reference. It mentions the locations:

  • CSIDL_APPDATA
  • CSIDL_LOCAL_APPDATA
  • CSIDL_COMMON_APPDATA

In native code, the method SHGetKnownFolderPath should prove useful.

In managed code you can use Environment.GetFolderPath(). If you're in a specific application framework, such as windows forms, you can get even easier access via direct properties, such as Application.LocalUserAppDataPath (which is my personal favorite technique). The framework path will include app-specific qualifiers on the path it returns to distinguish between (e.g.) different versions of your app.

like image 33
Greg D Avatar answered Sep 25 '22 09:09

Greg D