• Welcome to PlanetSquires Forums.
 

CWinHttpRequest

Started by Paul Squires, January 02, 2019, 08:59:58 PM

Previous topic - Next topic

Paul Squires

Hi Jose,

I have been thinking of adding an automated check for new WinFBE version. Your code below works perfectly but it does trigger Windows UAC so I have to click yes to continue. The file does download perfectly but obviously I don't want to have the user have to click all the time. Any thoughts? Maybe a setting or additional info that needs to be set?

Thanks,
Paul


'#CONSOLE ON
#include once "windows.bi"
#include once "Afx/CWinHttpRequest.inc"
#include once "Afx/CStream.inc"
using Afx

' // Create an instance of the CWinHttp class
DIM pWHttp AS CWinHttpRequest

' // Open an HTTP connection to an HTTP resource
pWHttp.Open "GET", "https://www.planetsquires.com/winfbe_version.txt"

' // Send an HTTP request to the HTTP server
pWHttp.Send

' // Wait for response with a timeout of 5 seconds
DIM iSucceeded AS LONG = pWHttp.WaitForResponse(5)

DIM st AS STRING = pWHttp.GetResponseBody
' // Open a file stream
DIM pFileStream AS CFileStream
IF pFileStream.Open("winfbe_version.txt", STGM_CREATE OR STGM_WRITE) = S_OK then
   pFileStream.WriteTextA(st)
END IF

PRINT
PRINT "Press any key..."
SLEEP

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

In my computer it doesn't trigger the UAC.

Paul Squires

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

If I set my UAC to the lowest setting then I don't get the notification but if I set it to any other level then it triggers.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Believe it or not, but it is the name of the EXE that is the problem. I named my test source code file "CheckForUpdate.bas". The resulting EXE automatically triggers the UAC. I guess EXE's named "CheckForUpdate.exe" must have special status. Anyway, seems to be working okay now that I am using a different filename.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

It is the Update word (there are some others, but I don't have a list) which makes trouble. I had to rename an ADO example called UpdateRecord as UpdatRecord.

Paul Squires

Here is another one for you just before I go to bed (big snowstorm here today so I have to get up early to handle the snow). It took me awhile to recreate the cause but it happens if AfxGdiplus.inc is placed before CWinHttpRequest.inc in the list of Includes.


#include once "windows.bi"
#Include Once "Afx\AfxGdiplus.inc"
#include once "Afx/CWinHttpRequest.inc"
#include once "Afx/CStream.inc"



FreeBASIC Compiler - Version 1.06.0 (11-22-2018), built for win32 (32bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
standalone
target:       win32, 486, 32bit
compiling:    X:\FB\WinFBE\src\WinFBE.bas -o X:\FB\WinFBE\src\WinFBE.asm (main module)
X:\FB\WinFBE_Suite-Editor\FreeBASIC-1.06.0\inc\Afx\CWinHttpRequest.inc(370) error 120: Expected period ('.'), found 'AS' in 'DIM status AS LONG'
X:\FB\WinFBE_Suite-Editor\FreeBASIC-1.06.0\inc\Afx\CWinHttpRequest.inc(371) error 42: Variable not declared, status in 'IF m_pWinHttp THEN SetResult(m_pWinHttp->get_Status(@status))'
X:\FB\WinFBE_Suite-Editor\FreeBASIC-1.06.0\inc\Afx\CWinHttpRequest.inc(372) error 9: Expected expression, found 'status' in 'RETURN status'
X:\FB\WinFBE_Suite-Editor\FreeBASIC-1.06.0\inc\Afx\CWinHttpRequest.inc(373) warning 13(0): Function result was not explicitly set

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Maybe there is an Status enumeration in the messy FB's GDI+ headers.

Change it to:


PRIVATE FUNCTION CWinHttpRequest.GetStatus () AS LONG
   DIM _status AS LONG
   IF m_pWinHttp THEN SetResult(m_pWinHttp->get_Status(@_status))
   RETURN _status
END FUNCTION

Paul Squires

Thanks José, that works perfectly. I will be sure to download an install your latest WinFBX into the WinFBE Suite before I release my next version.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Found on the web (if I had used a manifest file with my test code then I probably would have been okay):  :)

Quote
Due to the Installer Detection Technology of UAC, a UAC shield icon will be displayed on your 32-bit executable file with no requestedExecutionLevel in the manifest, but with keywords like “install”, “setup”, “update” etc in the filename.  With the UAC shield icon, if we launch the executable file, the UAC elevation dialog will pop up.

This feature is started from Windows Vista.  Windows 7 has similar Installer Detection Technology.

For additional information, please see the Installer Detection Technology section in http://technet.microsoft.com/en-us/library/cc709628(WS.10).aspx, and

http://blogs.msdn.com/sajoshi/archive/2007/02/22/uac-five-most-common-install-failure-scenarios-and-workarounds.aspx.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer