Correct way to design around Windows UAC limitations?

后端 未结 2 1188
北恋
北恋 2020-12-31 21:38

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 progr

相关标签:
2条回答
  • 2020-12-31 22:00

    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.

    0 讨论(0)
  • 2020-12-31 22:06

    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.

    0 讨论(0)
提交回复
热议问题