What is the Future of Winbatch / IE / OLE Programming?

Started by mcjathan, September 09, 2019, 03:15:15 PM

Previous topic - Next topic

mcjathan

Unless I'm mistaken, Internet Explorer will be phased out (after Windows 10?).  If I've missed this conversation somewhere else in this forum, would someone please point me there?

Otherwise, what are fellow Winbatch users' plans to transition their Winbatch scripts to other browsers or tools?

JTaylor

I have been experimenting with C# and the WebBrowser control.   Of course one can use that in WinBatch but it tends to lock up at times unless one initiates a Display(), Message(), etc. which isn't ideal and sometimes quite problematic.   With C# the DoEvents() clears the pipeline so things proceed.

Jim

td

Quote from: mcjathan on September 09, 2019, 03:15:15 PM
Unless I'm mistaken, Internet Explorer will be phased out (after Windows 10?).  If I've missed this conversation somewhere else in this forum, would someone please point me there?

Otherwise, what are fellow Winbatch users' plans to transition their Winbatch scripts to other browsers or tools?

Windows 10 is going to be around for a while and Internet Explorer ( the executable Web browser) is going to be available in it according to the MSFT's IE product life cycle.  But that really isn't the point.  COM Automation and the HTTP/HTML/DOM COM Automation interfaces used in many WinBatch scripts is deeply embedded into the OS  so even if IE the browser goes away, MSFT isn't going to remove those objects and their interface unless they did something very radical like completely dumping Windows and switching to the Linux kernel. 

Given that MSFT's IE replacement, the Edge browser, uses Google's Chrome rendering engine already, I guess that isn't completely out of the realm of possibility but the loss of IE would be the least of the issues that kind of radical change would generate.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Quote from: JTaylor on September 09, 2019, 04:52:20 PM
I have been experimenting with C# and the WebBrowser control.   Of course one can use that in WinBatch but it tends to lock up at times unless one initiates a Display(), Message(), etc. which isn't ideal and sometimes quite problematic.   With C# the DoEvents() clears the pipeline so things proceed.

Jim

Using Display or Message to "clear the pipeline" was an old kludge that should no longer be necessary.  If you can provide an example that requires that approach we will look into it.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Maybe I need to go back and try again???   I think I switched everything that had that problem to automate IE directly so as to avoid such issues.   Will let you know if I see that again.  Thanks.

Jim

mcjathan

I just learned from a vendor who uses IE that Microsoft is dropping support for IE on June 15 2022.  We have a number of operational Winbatch scripts that use IE OLE programming.  I'm looking for a direction to take these Winbatch scripts.  Suggestions?

td

It all depends on what you are using IE COM Automation for. While IE the application may be going away many of the Web-related COM Automation objects are not.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mcjathan

What our current Winbatch / IE / OLE scripts are doing is logging into a website, and then downloading file / documents, and then logging off.  Is there a way to do this without IE?

td

Yes but the degree of difficulty depends on the Website. If the site HTML elements you need to perform the task do not involve the execution of javascript, the solution is relatively simple. You could use the aforementioned COM Autionation objects, the Inet WIL extender, or WIL CLR hosting. There are examples of all these techniques on this forum and in the Tech Database.

If you need to execute javascript then it can get complicated. You will need to use some third-party software whether that is automating a Web browser or some HTML testing/scraping tool.  If you search this forum, you will find several discussions on this topic. But since I tend to rely on Website APIs for that kind of task, I can't offer any more specific advice or recommendations. Perhaps another forum user will chime in.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl


JTaylor

If the browser control doesn't go away then you may be good with embedding "Shell.Explorer.2" in a dialog.   Easy enough to test now before the IE option goes away.

While pricey, WebKitX, might be an option, if you need a full-blown browser control that handles Javascript.

Jim

....IFICantBYTE

For automating Edge, and other Chrome based browsers "without installing anything", check out this project I came across, and the underlying CDP stuff it uses...

I'm sure someone could get this going in Winbatch.

Simple Project: https://www.codeproject.com/Tips/5307593/Automate-Chrome-Edge-using-VBA
JASON parsing code it uses : https://github.com/VBA-tools/VBA-JSON
Chrome Dev Tools Protocol:  https://chromedevtools.github.io/devtools-protocol/
Regards,
....IFICantBYTE

Nothing sucks more than that moment during an argument when you realize you're wrong. :)

stanl

I wouldn't discount Excel/Power Query for web scraping and content forming. Below uses another pretty interesting URL:
Code (WINBATCH) Select


;Winbatch 2021c - Testing Excel Power Query for simple Web Scrape
;Requires Excel 2016 or Higher or Power Query added to Excel 2013 or earlier
;Stan Littlefield July 11, 2021
IntControl(73,1,0,0,0)
gosub udfs
qry = "Raleigh" ;gets city for URL's weather; also is tab name in Excel
cn = "Query - ":qry
mcode = getmcode()
BoxOpen("Please Wait","Creating Excel Power Query for Web Data")
toExcel()
BoxShut()
Pause("Query Completed","Save Workbook or Quit Excel")


Exit
;======================================================================================================
:WBERRORHANDLER
Terminate(@TRUE,"Error Encountered",geterror())
;======================================================================================================
:CANCEL
Display(2,"Operation Canceled","Goodbye...")
Exit
:udfs
#DefineSubRoutine geterror()
   wberroradditionalinfo = wberrorarray[6]
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
   Return(errmsg)
#EndSubRoutine


#DefineSubRoutine getmcode()
;M Code could be loaded from text file
;but if using WB's multi line, special chars must be escaped
code = $"
let
    Source = Web.Page(Web.Contents("https:://www.timeanddate.com/weather/usa/|city|")),
    Data0 = Source{0}[Data]
in
    Data0
$"
code = StrReplace(code,"|city|",qry)
Return(code)
#EndSubRoutine


#DefineSubRoutine toExcel()
oXL = CreateObject("Excel.Application")
If oXL == 0 Then Terminate(@TRUE,"Script Will Terminate","Cannot Start Excel Instance")
oXL.Visible          = @TRUE  ; change this to @FALSE to run hidden
oXL.ScreenUpdating   = @TRUE  ; if running hidden, change this to @FALSE
oXL.UserControl      = @TRUE
oXL.DisplayAlerts    = @FALSE
oXL.WorkBooks.Add()
oWS = oXL.ActiveWorkBook.Worksheets(1)
oWS.Activate()
oWS.Name = qry
oXL.ActiveWorkBook.Queries.Add(::Name=qry,Formula=mcode,Description="Json Query")
cSource = "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=%qry%;Extended Properties=''"
qt = oWS.ListObjects.Add(::SourceType=0,Source=cSource,Destination=oWS.Range("$A$1")).QueryTable
qt.CommandText = "Select * FROM [%qry%]"
qt.Refresh()
;may take some time but should save
;oXL.ActiveWorkbook.SaveAs(cXLS)
;oXL.ActiveWorkbook.Close()
;oXL.Quit()
oWS=0
oXL=0
Return(1)
#EndSubRoutine




Return






mcjathan

I recently learned that Microsoft Edge is offering an "IE Mode" which if I understand correctly offers some backwards compatibility for IE 11 OLE programming.  I'm wondering: have any Winbatch users explored this?

stanl

My understanding is IE mode has to be enabled prior to any use. Not sure if any of the DOM properties/methods can then be scripting to navigate of access data. Maybe worth exploring.

jmburton2001

Quote from: stanl on June 06, 2022, 07:35:17 AMMy understanding is IE mode has to be enabled prior to any use.

I had to enable IE mode for a particular URL a few months ago. It appears to be persistent because I haven't had to enable it for that URL since. It's just autoMAGICally in IE mode when I visit.