问题
My app needs to install some files that can be edited by the application at run time. Install shield provides an alias [CommonAppDataFolder] that will resolve to c:\programData on Vista and Windows 7 and will also work on Windows XP. Is there a win32 function that will return a similar path?
Maybe I need to call different functions depending on the operating system?
回答1:
SHGetFolderPath/SHGetSpecialFolderPath
get you that, with CSIDL_COMMON_APPDATA
argument.
See code snippet here (at the bottom): How to write a Windows XP Application that stores user and application data in the correct location by using Visual C++ .
- Windows XP: C:\Documents and Settings\All Users\Application Data
- Windows Vista: C:\ProgramData
- Windows 7: C:\ProgramData
See also: CSIDL.
回答2:
Since Delphi XE5, this functionality is part of the framework.
- Unit:
System.IOUtils
- Class:
TPath
- Function:
GetPublicPath
See embarcadero docwiki for further informations.
来源:https://stackoverflow.com/questions/11196151/win32-function-to-get-path-to-c-programdata