Page 1 of 1

Get download folder from registry

Posted: Thu Jul 01, 2021 7:38 am
by skiman
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.

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

Re: Get download folder from registry

Posted: Thu Jul 01, 2021 7:56 am
by skiman
In addition,

When the result is positive, there should be some pointer where the path can be found. So cPath won't be filled with a path, but with some pointer.

I don't know how to get the value of that pointer.

Looks as Microsoft made this kind of simple things quite difficult. :(

Re: Get download folder from registry

Posted: Thu Jul 01, 2021 8:19 am
by Eugene Lutsenko
In my program: http://lc.kubagro.ru/__AidosALL.txt I use downloading from the hosting and writing to it. To do this, I used to use Boris Borzik's xb2net, and now I do it using standard Alaska 2.0 tools. Downloading is possible both via http and ftp protocols. An example can be found in the function "FUNCTION F6_9()". The downloaded file always appears in the folder where the system is running (not in the download folder).

Re: Get download folder from registry

Posted: Thu Jul 01, 2021 8:51 am
by skiman
Hi,

In this case the invoices are downloaded in an external system, where the users have no choice where to download, it is downloaded in the default folder. It is working as a browser, downloads are automatically in the default folder.

To process these invoices with my application, I need to read the download folder. It would be a good solution if I can determine the location of this folder without any user intervention.

Re: Get download folder from registry

Posted: Thu Jul 01, 2021 12:49 pm
by Auge_Ohr
hi,

as i can say there is NO "Download Path" in Registry.

you can use Windows "default"

Code: Select all

%USERPROFILE%\Downloads

Re: Get download folder from registry

Posted: Sun Jul 04, 2021 11:44 pm
by skiman
Hi Jimmy,

There IS a download path in the registry. Just search the above GUID with regedit.

With %userprofile%\downloads you aren't sure you have the right folder, a user can place his downloads folder where he wants. As you said, it is the default, which is probably in most cases correct.