Results 1 to 8 of 8

Thread: [RESOLVED] All Users/Application Data

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    54

    Resolved [RESOLVED] All Users/Application Data

    Does anyone know how to programatically find the path to the above directory please?

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: All Users/Application Data

    Quote Originally Posted by slaphead109
    Does anyone know how to programatically find the path to the above directory please?

    Take a look at this LINK
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: All Users/Application Data

    Well, you can get to the user's AppData folder by using %appdata%, but if you want it for All Users, you can try something like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    4.  
    5. Private Function WindowsDir() As String
    6.     Dim lonRet As Long, strDir As String * 255
    7.    
    8.     lonRet = GetWindowsDirectory(strDir, 255)
    9.    
    10.     If lonRet <> 0 Then
    11.         WindowsDir = Left$(strDir, lonRet)
    12.     End If
    13.    
    14. End Function
    15.  
    16. Private Function AppDataFolder() As String
    17.     AppDataFolder = Left$(WindowsDir, 3) & "Documents And Settings\All Users\Application Data\"
    18. End Function
    19.  
    20. Private Sub Form_Load()
    21.     MsgBox AppDataFolder
    22. End Sub

    Maybe not the best way to do it though...

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: All Users/Application Data

    The Documents and Settings folder isn't named Documents and Settings on all locals. Use the following code instead:
    VB Code:
    1. Private Declare Function SHGetSpecialFolderPath _
    2.  Lib "shell32.dll" Alias "SHGetSpecialFolderP7athA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal pszPath As String, _
    5.     ByVal csidl As Long, _
    6.     ByVal fCreate As Long _
    7. ) As Long
    8.  
    9. Public Function AppDataPath() As String
    10.     Dim sPath As String
    11.     Const CSIDL_COMMON_APPDATA As Long = &H23
    12.     sPath = String(260, vbNullChar)
    13.     Call SHGetSpecialFolderPath(0, sPath, CSIDL_COMMON_APPDATA, 0)
    14.     AppDataPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
    15. End Function

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: All Users/Application Data

    Quote Originally Posted by Joacim Andersson
    The Documents and Settings folder isn't named Documents and Settings on all locals. Use the following code instead:
    VB Code:
    1. Private Declare Function SHGetSpecialFolderPath _
    2.  Lib "shell32.dll" Alias "SHGetSpecialFolderP7athA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal pszPath As String, _
    5.     ByVal csidl As Long, _
    6.     ByVal fCreate As Long _
    7. ) As Long
    8.  
    9. Public Function AppDataPath() As String
    10.     Dim sPath As String
    11.     Const CSIDL_COMMON_APPDATA As Long = &H23
    12.     sPath = String(260, vbNullChar)
    13.     Call SHGetSpecialFolderPath(0, sPath, CSIDL_COMMON_APPDATA, 0)
    14.     AppDataPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
    15. End Function
    Got an error

    Can't find DLL entry point SHGetSpecialFolderP7athA in shell32.dll
    Edit: Fixed the typo (7) in the API declaration and it works.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: All Users/Application Data

    Sorry about the typo.... Must have inserted the 7 by mistake

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    54

    Re: All Users/Application Data

    Great Job guys,

    Thanks.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] All Users/Application Data

    Please dont post duplicate threads.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width