2023-02-11, 10:06:39
With dBase, the browser pid is a numeric value.
With VBScript, not have the browser pid.
The way possible is to put in an array the pid of the msedgewebview2.exe before load the antview activeX.
I use the Win32_Process class to do this.
My tool to test with vbscript ( file.vbs )
With VBScript, not have the browser pid.
The way possible is to put in an array the pid of the msedgewebview2.exe before load the antview activeX.
I use the Win32_Process class to do this.
My tool to test with vbscript ( file.vbs )
Code:
' Test de AntView ocx with VBScript.
' This code is a basic sample.
' Defaults :
' 1 - Can not use the default webview2 folder ( CreateWebView() failed ).
' 2 - Error "violation memory" in line :
' Set EdgeWebBrowser = Wscript.CreateObject( "AntViewAx.Antview", "EdgeWebBrowser_" )
' but works.
' Using 2023-02-10 :
' - Windows 10 up to date.
' - AntWiew ocx 1.1.236.
option explicit
Const ct_cUrl = "https://www.cabinet-louis-reynaud.eu/index.php/clr-labs-3/" ' URL to use.
'Const ct_cUrl = "https://antview.dev/" ' URL to use.
'Const ct_cUrl = "https://www.google.fr/" ' URL to use.
Const ForWriting = 2
Const TristateTrue = -1
Public pu_cHtml : pu_cHtml = bv_DirBase() & "\_Result_html.txt" ' TXT source file created.
Public pu_cPdf : pu_cPdf = bv_DirBase() & "\_Result_pdf.pdf" ' PDF file created.
Public pu_cProp : pu_cProp = bv_DirBase() & "\_Result_Properties.txt" ' TXT EdgeWebBrowser properties file created.
Public pu_cWeb : pu_cWeb = "c:\Url_UserDataFolder" ' Webview2 files folder.
Public pu_nSpace : pu_nSpace = 37 ' Spaces in the EdgeWebBrowser properties functions.
Public pu_nEvent ' Indicate when the event function is finish.
' 0 = In work.
' 1 = Finshed ok.
' 2 = Finished fail.
Dim cJscript ' Script to execute.
Dim cProperties ' Variable for the EdgeWebBrowser properties
Dim Document ' AntViewAx.AntViewDocument object.
Dim EdgeWebBrowser ' AntViewAx.Antview object.
Dim i ' Count variable.
' Erase the old files.
bv_fErase( pu_cPdf )
bv_fErase( pu_cHtml )
bv_fErase( pu_cProp )
' Create a directory for the user datas, not works with the default folder.
bv_Makedir( pu_cWeb )
' Error Violation memory, no exception.
On Error Resume Next
Set EdgeWebBrowser = Wscript.CreateObject( "AntViewAx.Antview", "EdgeWebBrowser_" )
If Err.Number <> 0 Then
MsgBox( "***Error = " & Err.Number & " Description = " & Err.Description )
Err.Clear
End If
On Error GoTo 0
' CreateWebView() failed if use defaut directory.
EdgeWebBrowser.UserDataFolder = pu_cWeb
EdgeWebBrowser.CreateWebView
For i = 1 to 60 Step 1
if EdgeWebBrowser.WebViewCreated Then Exit For
wscript.sleep 1000
Next
If not EdgeWebBrowser.WebViewCreated Then
Set EdgeWebBrowser = Nothing
MsgBox "WebViewCreated() fail !"
wscript.Quit
End If
Set Document = Wscript.CreateObject( "AntViewAx.AntViewDocument", "Document_" )
Document.BrowserDispatch( EdgeWebBrowser.IDispatchPointer )
' Open the URL.
pu_nEvent = 0
EdgeWebBrowser.Navigate( ct_cUrl )
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
wscript.sleep 1000
Next
If pu_nEvent <> 1 Then
MsgBox "Navigate() fail !"
EdgeWebBrowser.CloseBrowserProcess
EdgeWebBrowser.CloseWebView
Set EdgeWebBrowser = Nothing
Set Document = Nothing
wscript.quit
End If
' Accept cookies.
' Thanks to Wila : https://forums.antwise.com/showthread.php?tid=147
If ct_cUrl = "https://www.cabinet-louis-reynaud.eu/index.php/clr-labs-3/" Then
cJscript = "var button = document.getElementsByClassName(""cmplz-accept"");" & vbCrLf
cJscript = cJscript & "button[0].click();"
ElseIf ct_cUrl = "https://www.google.fr/" then
cJscript = "var button = document.getElementsByClassName(""QS5gu sy4vM"");" & vbCrLf
cJscript = cJscript & "button[1].click();" ' button[0] = not accept.
End If
If Not IsEmpty( cJscript ) Then
pu_nEvent = 0
EdgeWebBrowser.ExecuteScript cJscript
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
wscript.sleep 1000
Next
wscript.sleep 1000
End If
' Print to PDF.
pu_nEvent = 0
EdgeWebBrowser.PrintToPdf pu_cPdf, ""
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
wscript.sleep 1000
Next
' Get HTML source.
pu_nEvent = 0
Document.RequestCurrentHtml()
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
wscript.sleep 1000
Next
' List EdgeWebBrowser properties.
cProperties = "EdgeWebBrowser properties." & vbCrLf
cProperties = cProperties & "!" & String( pu_nSpace , "-" )& "!-------------!" & vbCrLf
cProperties = cProperties & "!Name" & String( pu_nSpace - 4, " ") & "!Type !Value" & vbCrLf
cProperties = cProperties & "!" & String( pu_nSpace , "-") & "!-------------!" & vbCrLf
On Error Resume Next : cProperties = cProperties & WriteProperty( "Active" , EdgeWebBrowser.Active ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AdditionalBrowserArguments" , EdgeWebBrowser.AdditionalBrowserArguments ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AlignDisabled" , EdgeWebBrowser.AlignDisabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AlignWithMargins" , EdgeWebBrowser.AlignWithMargins ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AllowSingleSignOnUsingOSPrimaryAccount", EdgeWebBrowser.AllowSingleSignOnUsingOSPrimaryAccount ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AlignDisabled" , EdgeWebBrowser.AlignDisabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AutoScroll" , EdgeWebBrowser.AutoScroll ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AutoSize" , EdgeWebBrowser.AutoSize ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "AxBorderStyle" , EdgeWebBrowser.AxBorderStyle ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "BorderWidth" , EdgeWebBrowser.BorderWidth ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "BrowserAcceleratorKeysEnabled" , EdgeWebBrowser.BrowserAcceleratorKeysEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "BrowserProcessID" , EdgeWebBrowser.BrowserProcessID ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "BrowserVersionString" , EdgeWebBrowser.BrowserVersionString ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "BuiltInErrorPageEnabled" , EdgeWebBrowser.BuiltInErrorPageEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "CanGoBack" , EdgeWebBrowser.CanGoBack ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "CanGoForward" , EdgeWebBrowser.CanGoForward ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Caption" , EdgeWebBrowser.Caption ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Color" , EdgeWebBrowser.Color ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ContainsFullScreenElement" , EdgeWebBrowser.ContainsFullScreenElement ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Controller" , EdgeWebBrowser.Controller ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "CreateWebViewOnCreate" , EdgeWebBrowser.CreateWebViewOnCreate ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "CurrentPPI" , EdgeWebBrowser.CurrentPPI ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DefaultContextMenusEnabled" , EdgeWebBrowser.DefaultContextMenusEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DefaultInterface" , EdgeWebBrowser.DefaultInterface ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DefaultScriptDialogsEnabled" , EdgeWebBrowser.DefaultScriptDialogsEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DefaultUserDataFolderLocation" , EdgeWebBrowser.DefaultUserDataFolderLocation ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DemoDaysLeft" , EdgeWebBrowser.DemoDaysLeft ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DevToolsEnabled" , EdgeWebBrowser.DevToolsEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DockSite" , EdgeWebBrowser.DockSite ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DocumentTitle" , EdgeWebBrowser.DocumentTitle ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DoubleBuffered" , EdgeWebBrowser.DoubleBuffered ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DownloadDialogCornerAlignment" , EdgeWebBrowser.DownloadDialogCornerAlignment ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "DropTarget" , EdgeWebBrowser.DropTarget ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Enabled" , EdgeWebBrowser.Enabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Environment" , EdgeWebBrowser.Environment ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "EventsUseHexadecimal" , EdgeWebBrowser.EventsUseHexadecimal ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ExplicitHeight" , EdgeWebBrowser.ExplicitHeight ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ExplicitLeft" , EdgeWebBrowser.ExplicitLeft ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ExplicitTop" , EdgeWebBrowser.ExplicitTop ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ExplicitWidth" , EdgeWebBrowser.ExplicitWidth ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Font" , EdgeWebBrowser.Font ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "GeneralAutofillEnabled" , EdgeWebBrowser.GeneralAutofillEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "HelpFile" , EdgeWebBrowser.HelpFile ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "IDispatchPointer" , EdgeWebBrowser.IDispatchPointer ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "KeyPreview" , EdgeWebBrowser.KeyPreview ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Language" , EdgeWebBrowser.Language ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "LastErrorCode" , EdgeWebBrowser.LastErrorCode ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "LastErrorMessage" , EdgeWebBrowser.LastErrorMessage ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "MouseInClient" , EdgeWebBrowser.MouseInClient ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "NextFocusWindowHandle" , EdgeWebBrowser.NextFocusWindowHandle ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "NextFocusWindowHandleUInt" , EdgeWebBrowser.NextFocusWindowHandleUInt ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PasswordAutosaveEnabled" , EdgeWebBrowser.PasswordAutosaveEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PixelsPerInch" , EdgeWebBrowser.PixelsPerInch ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PopupMode" , EdgeWebBrowser.PopupMode ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PreviousFocusWindowHandle" , EdgeWebBrowser.PreviousFocusWindowHandle ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PreviousFocusWindowHandleUInt" , EdgeWebBrowser.PreviousFocusWindowHandleUInt ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "PrintScale" , EdgeWebBrowser.PrintScale ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Scaled" , EdgeWebBrowser.Scaled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ScaleFactor" , EdgeWebBrowser.ScaleFactor ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ScreenSnap" , EdgeWebBrowser.ScreenSnap ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ScriptEnabled" , EdgeWebBrowser.ScriptEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Settings" , EdgeWebBrowser.Settings ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "SizeRatio" , EdgeWebBrowser.SizeRatio ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "SnapBuffer" , EdgeWebBrowser.SnapBuffer ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "Source" , EdgeWebBrowser.Source ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "StatusBarEnabled" , EdgeWebBrowser.StatusBarEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "SynchronousTimeOut" , EdgeWebBrowser.SynchronousTimeOut ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "TargetCompatibleBrowserVersion" , EdgeWebBrowser.TargetCompatibleBrowserVersion ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "UseDockManager" , EdgeWebBrowser.UseDockManager ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "UserAgent" , EdgeWebBrowser.UserAgent ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "UserDataFolder" , EdgeWebBrowser.UserDataFolder ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "VersionString" , EdgeWebBrowser.VersionString ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "WebMessageEnabled" , EdgeWebBrowser.WebMessageEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "WebResourceResponseReceivedEnabled" , EdgeWebBrowser.WebResourceResponseReceivedEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "WebView2LoaderPath" , EdgeWebBrowser.WebView2LoaderPath ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "WebViewCreated" , EdgeWebBrowser.WebViewCreated ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "WindowClosedRequestEnabled" , EdgeWebBrowser.WindowClosedRequestEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ZoomControlEnabled" , EdgeWebBrowser.ZoomControlEnabled ) : Err.Clear : On Error GoTo 0
On Error Resume Next : cProperties = cProperties & WriteProperty( "ZoomFactor" , EdgeWebBrowser.ZoomFactor ) : Err.Clear : On Error GoTo 0
cProperties = cProperties & "!" & String( pu_nSpace , "-") & "!-------------!" & vbCrLf
bv_MemoWrit pu_cProp, cProperties
' Close the browser and clear memory.
EdgeWebBrowser.CloseBrowserProcess
EdgeWebBrowser.CloseWebView
Set EdgeWebBrowser = Nothing
Set Document = Nothing
MsgBox "End of script, look the created files."
' ***** Function *****
Function WriteProperty( cName, xProperty )
Dim cStringe ' String created.
cStringe = "!" & cName & String( pu_nSpace - Len( cName ), " ") & "!"
cStringe = cStringe & TypeName( xProperty ) & String( 13 - Len( TypeName ( xProperty ) ), " ") & "!"
WriteProperty = cStringe & xProperty & vbCrLf
End Function
' ***** Event functions *****
Sub Document_OnRequestCurrentHtml( cHtml )
pu_nEvent = 1
bv_MemoWrit pu_cHtml, cHtml
End Sub
Sub EdgeWebBrowser_OnExecuteScript( HResult, JsonObject )
If HResult = 0 Then
pu_nEvent = 1
Else
pu_nEvent = 2
MsgBox "OnExecuteScript() fail, HResult = ] " & HResult
End If
End Sub
Sub EdgeWebBrowser_OnNavigationCompleted( IsSuccess, WebErrorStatus, NavigationId )
If IsSuccess Then
pu_nEvent = 1
Else
pu_nEvent = 2
End If
End Sub
Sub EdgeWebBrowser_OnPrintToPdfCompleted( HResult, IsSuccessful )
If IsSuccessful Then
pu_nEvent = 1
Else
pu_nEvent = 2
MsgBox "OnPrintToPdfCompleted() fail, HResult = ] " & HResult
End If
End Sub
' ***** Used tools *****
' Get the default directory.
Function bv_DirBase()
bv_DirBase = Left( WScript.ScriptFullName, InStrRev( WScript.ScriptFullName, "\" ) )
End Function
' Erase a file.
Sub bv_fErase( cFile_bv )
Dim oFso_bv
Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
If oFso_bv.FileExists( cFile_bv ) Then
oFso_bv.DeleteFile cFile_bv
End If
Set oFso_bv = Nothing
End Sub
' Create a directory.
Sub bv_Makedir( cDir_bv )
Dim oFso_bv
Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
If Not oFso_bv.FolderExists( cDir_bv ) Then
oFso_bv.CreateFolder( cDir_bv )
End If
Set oFso_bv = Nothing
End Sub
' Write a string in a file.
Sub bv_MemoWrit( cFile_bv, cString_bv )
Dim oFile_bv
Dim oFso_bv
Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
If oFso_bv.FileExists( cFile_bv ) Then
oFso_bv.DeleteFile cFile_bv
End If
Set oFile_bv = oFso_bv.OpenTextFile( cFile_bv, ForWriting, True, TristateTrue )
oFile_bv.Write cString_bv
oFile_bv.Close
Set oFso_bv = Nothing
End Sub