|
-
Nov 27th, 2006, 07:02 AM
#1
Thread Starter
Member
[RESOLVED] All Users/Application Data
Does anyone know how to programatically find the path to the above directory please?
-
Nov 27th, 2006, 07:45 AM
#2
Re: All Users/Application Data
 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."
-
Nov 27th, 2006, 07:50 AM
#3
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:
Option Explicit
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Function WindowsDir() As String
Dim lonRet As Long, strDir As String * 255
lonRet = GetWindowsDirectory(strDir, 255)
If lonRet <> 0 Then
WindowsDir = Left$(strDir, lonRet)
End If
End Function
Private Function AppDataFolder() As String
AppDataFolder = Left$(WindowsDir, 3) & "Documents And Settings\All Users\Application Data\"
End Function
Private Sub Form_Load()
MsgBox AppDataFolder
End Sub
Maybe not the best way to do it though...
-
Nov 27th, 2006, 07:50 AM
#4
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:
Private Declare Function SHGetSpecialFolderPath _
Lib "shell32.dll" Alias "SHGetSpecialFolderP7athA" ( _
ByVal hWnd As Long, _
ByVal pszPath As String, _
ByVal csidl As Long, _
ByVal fCreate As Long _
) As Long
Public Function AppDataPath() As String
Dim sPath As String
Const CSIDL_COMMON_APPDATA As Long = &H23
sPath = String(260, vbNullChar)
Call SHGetSpecialFolderPath(0, sPath, CSIDL_COMMON_APPDATA, 0)
AppDataPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
End Function
-
Nov 27th, 2006, 07:57 AM
#5
Re: All Users/Application Data
 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:
Private Declare Function SHGetSpecialFolderPath _
Lib "shell32.dll" Alias "SHGetSpecialFolderP7athA" ( _
ByVal hWnd As Long, _
ByVal pszPath As String, _
ByVal csidl As Long, _
ByVal fCreate As Long _
) As Long
Public Function AppDataPath() As String
Dim sPath As String
Const CSIDL_COMMON_APPDATA As Long = &H23
sPath = String(260, vbNullChar)
Call SHGetSpecialFolderPath(0, sPath, CSIDL_COMMON_APPDATA, 0)
AppDataPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
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.
-
Nov 27th, 2006, 08:01 AM
#6
Re: All Users/Application Data
Sorry about the typo.... Must have inserted the 7 by mistake
-
Nov 28th, 2006, 04:01 AM
#7
Thread Starter
Member
Re: All Users/Application Data
-
Nov 28th, 2006, 04:25 AM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|