Get download folder from registry
Posted: Thu Jul 01, 2021 7:38 am
Hi,
I want to know the download folder to copy files in the background. A system my customers are using is downloading invoices in the download folder, without any possibility to get them in a predefined folder.
I tried via the registry, but you can't read the values. In the registry itself, there is a note that you have to use a specific function.
This is my code, but it doesn't work. Anyone who has more experience with this? I need to use the function SHGetKnownFolderPath which is in shell32.dll.
I want to know the download folder to copy files in the background. A system my customers are using is downloading invoices in the download folder, without any possibility to get them in a predefined folder.
I tried via the registry, but you can't read the values. In the registry itself, there is a note that you have to use a specific function.
This is my code, but it doesn't work. Anyone who has more experience with this? I need to use the function SHGetKnownFolderPath which is in shell32.dll.
Code: Select all
Function fGetPathDownloadfolder()
***************************************************************************************************
// GUID of download folder: 374DE290-123F-4565-9164-39C4925E467B
// In register: Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
// You can't get this value via the register. See the following note in the register when you open the Shell Folders via regedit.
// "!Do not use this registry key - Use the SHGetFolderPath or SHGetKnownFolderPath function instead"
// see also: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
Local nDll := DllLoad( "SHELL32.DLL" )
Local uResult , cPath := space(50)
IF nDll <> 0
// Call the API function
uResult := DllCall( nDll, DLL_STDCALL, ;
'SHGetKnownFolderPath', '374DE290-123F-4565-9164-39C4925E467B', 0,0,@cPath)
wtf uResult , cPath // this gives a negative number as result, cPath remains empty.
// Release DLL
DllUnload( nDll )
else
msgbox("DLL not loaded")
ENDIF
return nil