Page 1 of 1

Downloading EXE file from https

Posted: Thu Jan 16, 2020 4:30 pm
by serge_girard
For my applications I need to know if on the running computer AnyDesk and/or TeamViewer is installed.
In order to find if 'AnyDesk' is installed I do this:

Code: Select all

cANY := GetProgramFilesFolder() + '\ANYDESK\ANYDESK.EXE'
IF FILE(cANY) 
   MSGINFO('ANYDESK INSTALLED ') 
ELSE
   MSGINFO('ANYDESK NOT INSTALLED ')   // https://anydesk.com/nl 
ENDIF
This works fine. When not installed I need to automate the download procedure:
for AnyDesk:

https://download.anydesk.com/AnyDesk.exe

Now download will start after clicking 'Save file'. This I need to do without user intervention whatsoever.
Anybody how to do this?

Thanks, Serge

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 7:33 am
by mlnr
Hi Serge,

Please try this

Code: Select all

DownloadFile("https://download.anydesk.com/AnyDesk.exe?_ga=2.224258847.522008046.1579245845-896270655.1579245845","AnyDesk.exe")

Code: Select all

FUNCTION DownloadFile( cUrl, cFile ) 
    LOCAL oSoap, aRetorno, nHandle, nCont, lOk 

    lOk := .f. 
    BEGIN SEQUENCE WITH { |e| Break(e) } 
       oSoap := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" ) 
       oSoap:Open( "GET", cUrl, .f. ) 
       oSoap:Send() 
       aRetorno := oSoap:ResponseBody() 
       nHandle := fCreate( cFile ) 
       IF ValType( aRetorno ) == "C" 
          fWrite( nHandle, aRetorno ) 
       ELSE 
          FOR nCont = 1 TO Len( aRetorno ) 
             fWrite( nHandle, Chr( aRetorno[ nCont ] ) ) 
          NEXT 
       ENDIF 
       fClose( nHandle ) 
       oSoap:Close() 
       lOk := .t. 
    END SEQUENCE 
RETURN lOk
And maybe it's useful link to some parameter.

https://support.anydesk.com/Automatic_Deployment

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 8:41 am
by serge_girard
Thanks Gabor! I will try !

Serge

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 9:32 am
by RPC
mlnr wrote: Fri Jan 17, 2020 7:33 am Hi Serge,

Please try this

Code: Select all

DownloadFile("https://download.anydesk.com/AnyDesk.exe?_ga=2.224258847.522008046.1579245845-896270655.1579245845","AnyDesk.exe")

Code: Select all

FUNCTION DownloadFile( cUrl, cFile ) 
    LOCAL oSoap, aRetorno, nHandle, nCont, lOk 

    lOk := .f. 
    BEGIN SEQUENCE WITH { |e| Break(e) } 
       oSoap := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" ) 
       oSoap:Open( "GET", cUrl, .f. ) 
       oSoap:Send() 
       aRetorno := oSoap:ResponseBody() 
       nHandle := fCreate( cFile ) 
       IF ValType( aRetorno ) == "C" 
          fWrite( nHandle, aRetorno ) 
       ELSE 
          FOR nCont = 1 TO Len( aRetorno ) 
             fWrite( nHandle, Chr( aRetorno[ nCont ] ) ) 
          NEXT 
       ENDIF 
       fClose( nHandle ) 
       oSoap:Close() 
       lOk := .t. 
    END SEQUENCE 
RETURN lOk
And maybe it's useful link to some parameter.

https://support.anydesk.com/Automatic_Deployment
Hi mlnr
Thanks for youe code. Can you please tell me what is the significance of "?_ga=2.224258847.522008046.1579245845-896270655.1579245845" appearing in URL. I have found your code works with even with "https://download.anydesk.com/AnyDesk.exe" command.
Thanks

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 11:03 am
by mlnr
Can you please tell me what is the significance of "?_ga=2.224258847.522008046.1579245845-896270655.1579245845" appearing in URL. I have found your code works with even with "https://download.anydesk.com/AnyDesk.exe" command.
No. Just copied the download link from the Anyway webpage :)

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 1:26 pm
by serge_girard
Gabor,

I used this working sample:

Code: Select all

#include "hmg.ch"
 
/* AD.HBC file 
inc=yes
head=native
libs=libhpdf
libs=png
libs=hbssl
libs=libeay32
libs=ssleay32
*/

/* AD.HBP file
AD.PRG   (this program!)
hbssl.hbc
*/

 

FUNCTION MAIN()
/***************/
PUBLIC cANY             := ''
PUBLIC WshShell			:= CreateObject("WScript.Shell")
PUBLIC DesktopFolder		:= WshShell:SpecialFolders("Desktop")

#require "hbtip"
#require "hbssl"
REQUEST __HBEXTERN__HBSSL__

cANY := DesktopFolder + '\ANYDESK.EXE'
IF FILE(cANY) 
   MSGINFO('ANYDESK allready installed')
ELSE   
   Get_IP_Via_PS('ANYDESK')
   MSGINFO('Ready!  ANYDESK installed')
ENDIF
QUIT


FUNCTION Get_IP_Via_PS(XX)
/*************************************/
LOCAL cURL, cHtml, vRet, cX1, XHTTP


XHTTP := 'https://download.anydesk.com/AnyDesk.exe' 
cURL	:= XHTTP
cHtml	:= Read_URL_SG( cURL )
Buff_To_File(cHtml, cANY)
RETURN


FUNCTION Read_URL_SG( cUrl )
/***************************/
LOCAL oUrl, oCli, cRes := ''
// REQUEST __HBEXTERN__HBSSL__

BEGIN SEQUENCE
	oUrl = TUrl():New( cUrl )
	IF EMPTY( oUrl )
		BREAK
	ENDIF
	oCli = TIpClientHttp():New( oUrl )
	IF EMPTY( oCli )
		BREAK
	ENDIF
	oCli:nConnTimeout = 20000
	IF !oCli:Open( oUrl )
		BREAK
	ENDIF
	cRes := oCli:Read()
	oCli:Close()
END SEQUENCE
RETURN cRes


FUNCTION Buff_To_File(cBuff, cNEW_FILE)
/*************************************/
LOCAL fh, nLen

fh := FCREATE(cNEW_FILE,0)

IF fh > - 1
	nLen	:= FWRITE(fh, cBuff) 
	FCLOSE(fh)

	IF nLen == LEN(cBuff)
      RETURN .T.	 
	ELSE
		RETURN .F.
	ENDIF
ENDIF

RETURN .F.	 
This works for Anydesk but not for TeamViewer: I tried this

Code: Select all

XHTTP := 'https://www.teamviewer.com/nl/teamviewer-automatisch-downloaden' 
XHTTP := 'https://dl.teamviewer.com' 
XHTTP := 'https://download.teamviewer.com/full'  // ==>   'TeamViewer_Setup.exe'
Serge

Re: Downloading EXE file from https

Posted: Fri Jan 17, 2020 3:40 pm
by mlnr

Re: Downloading EXE file from https

Posted: Sat Jan 18, 2020 9:10 am
by serge_girard
Thanks Gabor, this works fine!

Serge