PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CWinHttpRequest  (Read 316 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
CWinHttpRequest
« on: January 02, 2019, 08:59:58 PM »

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

Code: [Select]
'#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
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3171
Re: CWinHttpRequest
« Reply #1 on: January 02, 2019, 09:15:20 PM »

In my computer it doesn't trigger the UAC.

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #2 on: January 02, 2019, 09:18:53 PM »

Hmmmm.... interesting.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #3 on: January 02, 2019, 09:22:01 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #4 on: January 02, 2019, 09:36:16 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3171
Re: CWinHttpRequest
« Reply #5 on: January 02, 2019, 10:16:10 PM »

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

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #6 on: January 02, 2019, 10:29:20 PM »

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.

Code: [Select]
#include once "windows.bi"
#Include Once "Afx\AfxGdiplus.inc"
#include once "Afx/CWinHttpRequest.inc"
#include once "Afx/CStream.inc"

Code: [Select]
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
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3171
Re: CWinHttpRequest
« Reply #7 on: January 02, 2019, 11:11:56 PM »

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

Change it to:

Code: [Select]
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

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #8 on: January 03, 2019, 04:32:45 AM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: CWinHttpRequest
« Reply #9 on: January 03, 2019, 02:05:06 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer