Does anyone know how to programatically find the path to the above directory please?
Printable View
Does anyone know how to programatically find the path to the above directory please?
Quote:
Originally Posted by slaphead109
Take a look at this LINK
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...
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 :(Quote:
Originally Posted by Joacim Andersson
Edit: Fixed the typo (7) in the API declaration and it works. ;)Quote:
Can't find DLL entry point SHGetSpecialFolderP7athA in shell32.dll
Sorry about the typo.... Must have inserted the 7 by mistake :)
Great Job guys,
Thanks.
Please dont post duplicate threads.