Win32 function to get path to C:\ProgramData

落花浮王杯 提交于 2019-12-20 17:59:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!