2012-06-25 53 views
10

我的應用程序需要安裝一些可以在運行時由應用程序編輯的文件。 Install Shield提供了一個別名[CommonAppDataFolder],它將解析爲Vista和Windows 7上的c:\ programData,並且也可以在Windows XP上使用。有沒有一個win32函數會返回類似的路徑?Win32函數獲取路徑到C: ProgramData

也許我需要根據操作系統調用不同的函數?

回答

18

SHGetFolderPath/SHGetSpecialFolderPath讓你知道,CSIDL_COMMON_APPDATA的論點。

查看此處的代碼片段(底部):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和Settings \所有用戶\應用數據
  • Windows Vista中:C:\ ProgramData
  • 的Windows 7:C:\ ProgramData

參見: CSIDL

+0

看來CSIDL_COMMON_APPDATA將解析爲:C:\ Documents and Settings \ All Users \ Application Data是否沒有辦法獲取到c:\ ProgramData的路徑?這不是一個存放這些文件的好地方嗎? – Mike2012

+1

@ Mike2012,兩條路徑都有相同的用途 - 一個用於XP及更低版本,另一個用於Vista及更高版本。所以你得到的結果取決於你使用的操作系統。 – eran

+1

查看上面 - 添加樣例路徑常量解決在不同的Windows版本 –