CommonAppData在vb6中

基本上和这个问题一样 ,但是对于VB6

客户的应用程序“AppName”的configuration文件存储在CommonAppData中。

  • Windows XP下是C:\ Documents and Settings \ All Users \ Application Data \ AppName
  • 在Windows Vista中是C:\ ProgramData \ AppName

如何获得正确的文件名与VB6?

额外的笔记 ,我喜欢使用API​​调用,而不是添加到shell32.dll的引用

使用迟绑定:

 Const ssfCOMMONAPPDATA = &H23 Dim strCommonAppData As String strCommonAppData = _ CreateObject("Shell.Application").NameSpace(ssfCOMMONAPPDATA).Self.Path 

找到了;

 Private Declare Function SHGetFolderPath _ Lib "shfolder.dll" Alias "SHGetFolderPathA" _ (ByVal hwndOwner As Long, _ ByVal nFolder As Long, _ ByVal hToken As Long, _ ByVal dwReserved As Long, _ ByVal lpszPath As String) As Long Private Const CSIDL_COMMON_APPDATA = &H23 Private Const CSIDL_COMMON_DOCUMENTS = &H2E Public Function strGetCommonAppDataPath() As String Dim strPath As String strPath = Space$(512) Call SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, 0, strPath) strPath = Left$(strPath, InStr(strPath, vbNullChar)) strGetCommonAppDataPath = strPath End Function 

Karl Peterson 发布了一个名为CSystemFolders的嵌入式 VB6类,它将查找CSIDL_APPDATA,CSIDL_LOCAL_APPDATA和CSIDL_COMMON_APPDATA。

卡尔的代码总是可靠的,不接受替代品:)