代码之家  ›  专栏  ›  技术社区  ›  DavRob60

vb6中的CommonAppData

  •  5
  • DavRob60  · 技术社区  · 16 年前

    基本上和这个一样 question 但为了 VB6 .

    客户的应用程序“AppName”具有 其配置文件存储在 通用数据。

    • 在Windows XP下,即C:\Documents and Settings\All 用户\应用程序数据\AppName
    • 在Windows Vista下,它是C:\ProgramData\AppName

    我怎样才能得到正确的折叠 VB6? ?

    附加说明 ,我更喜欢使用API调用,而不是添加对shell32.dll的引用。

    3 回复  |  直到 16 年前
        1
  •  8
  •   Bob77    16 年前

    使用后期绑定:

    Const ssfCOMMONAPPDATA = &H23
    Dim strCommonAppData As String
    
    strCommonAppData = _
        CreateObject("Shell.Application").NameSpace(ssfCOMMONAPPDATA).Self.Path
    
        2
  •  3
  •   DavRob60    16 年前

    找到了它;

    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
    
        3
  •  2
  •   MarkJ    16 年前

    卡尔·彼得森 published 一个名为 CSystemFolders 这将找到csidl-appdata、csidl-local-appdata和csidl-common-appdata。

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