i want msedgewebview2 process ID.. - hys999 - 2023-02-10
hello. First of all thank you so much for your help last time.
I have one question for you.
In the background when antview is started
Can I get the PID value of msedgewebview2.exe?
Because after using multiple antviews in different forms
If they are not properly terminated in terms of memory protection
I want to kill everyone by pid, but if I make a mistake, open in the main window
Sometimes the browser even dies.
So I want to exclude only the pid found in main and kill it.
RE: i want msedgewebview2 process ID.. - Bernard Mouille - 2023-02-10
Hello,
You have the process ID in EdgeWebBrowser.BrowserProcessID property.
Regards,
Bernard.
RE: i want msedgewebview2 process ID.. - hys999 - 2023-02-11
Thank you for answer. But in vb6.0
read the BrowserProcessID value, or
I can't even access it.
[Functions marked restricted or used as interfaces or automation forms are not supported in visual basic]
The variable type seems to be different, but I can't convert it to any format.
Please support with vb6.0 long or double type.
RE: i want msedgewebview2 process ID.. - Bernard Mouille - 2023-02-11
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 )
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
RE: i want msedgewebview2 process ID.. - wila - 2023-02-11
Hi,
Bernard already gave the answer that I was going to give so instead of repeating the answer, I just watched the thread.
You are correct about the runtime error in VB6, I just reproduced that here.
Code: ---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic
---------------------------
OK Help
---------------------------
Obviously that is not very useful when trying to use this property from within VB6.
This appears to be because VB6 does not support the "unsigned long" (unsigned integer) data type.
Let me have a look and see what the best solution is for this.
Thanks,
--
Wil
RE: i want msedgewebview2 process ID.. - wila - 2023-02-11
Hello again,
I checked it all and it seems like you got bitten by everyone being overly cautious.
The people at Microsoft have declared the BrowserProcessID as UInt32, so when we wrote the wrapper this was translated into an Unsigned Long for the ActiveX declaration.
At MSDN the ProcessID function is declared as a DWord.
I've never seen process ID's go over the integer boundary, although I suppose it is possible on a busy server.
As the easiest possible workaround I just figured to create a BrowserProcessIDLong alternative property.
That I can use from VB6 without issue.
eg.
Code: Private Sub PIDButton_Click()
Dim PID As Long
PID = EdgeWebBrowser.BrowserProcessIDLong
MsgBox ("Process ID = " & CStr(PID))
End Sub
There's a private version of AntView that you can currently download from:
edit: [removed private link] use released version 1.1.270 instead
That hopefully resolves your issue.
Let me know how it goes.
--
Wil
RE: i want msedgewebview2 process ID.. - Bernard Mouille - 2023-02-11
You can also take some idea in the code in CScript to look the msedgewebview2.exe loaded and kiill if you want.
Code: ' Test de AntView ocx with CScript.
' 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
' Run in CScript if it is running in VBScript to have the console.
If InStr( LCase( WScript.FullName ), "cscript.exe" ) = 0 Then
CreateObject( "WScript.Shell" ).Run "cscript.exe //NoLogo """ & WScript.ScriptFullName & ""
WScript.Quit
End If
Dim aUrls ' Array to choice on URL to use.
aUrls = Array( _
"https://www.cabinet-louis-reynaud.eu/index.php/clr-labs-3/" _
, "https://antview.dev/" _
, "https://www.google.fr/" _
)
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 cPids ' String for the msedgewebview2.exe old running.
Dim cProperties ' Variable for the EdgeWebBrowser properties
Dim cUrl ' URL to use.
Dim Document ' AntViewAx.AntViewDocument object.
Dim EdgeWebBrowser ' AntViewAx.Antview object.
Dim xChoice ' Choice of the URL to use.
Dim i ' Count variable.
bv_QOut( "AntView activeX test in CScript." )
bv_QOut( "" )
bv_QOut( "Old msedgewebview2.exe running PID(s) before kill :" )
cPids = bv_GetAllPidForExeRun( "msedgewebview2.exe" )
bv_QOut( cPids )
If Len( cPids ) > 0 Then
i = MsgBox( "Do you want to kill the old(s) msedgewebview2.exe ?", vbYesNo + vbQuestion, "Question" )
If i = vbYes Then
bv_QOut( "" )
bv_QOut( bv_KillAllExeByPids( cPids ) )
bv_QOut( "" )
bv_QOut( "Old msedgewebview2.exe running PID(s) after killed :" )
cPids = bv_GetAllPidForExeRun( "msedgewebview2.exe" )
bv_QOut( cPids )
bv_QOut( "" )
End If
End If
bv_QOut( "Select an URL to read :" )
bv_QOut( "" )
For i = LBound( aUrls ) to UBound( aUrls ) Step 1
bv_QOut( i & "->" & aUrls( i ) )
Next
bv_QQOut( "Select your URL : " )
xChoice = WScript.StdIn.ReadLine
xChoice = CLng( xChoice )
If xChoice < LBound( aUrls ) Or xChoice > UBound( aUrls ) Then
msgbox "Bad choice in select URL, abort."
wscript.Quit
End If
bv_QOut( "" )
bv_QOut( "URL selected :" )
cUrl = aUrls( xChoice )
bv_QOut( cUrl )
bv_QOut( "" )
' 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 )
bv_QOut( "Error Violation memory, no exception, click on << OK >>" )
bv_QOut( "" )
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
wscript.Quit
End If
On Error GoTo 0
' CreateWebView() failed if use defaut directory.
EdgeWebBrowser.UserDataFolder = pu_cWeb
bv_QOut( "Create the WebView." )
EdgeWebBrowser.CreateWebView
For i = 1 to 60 Step 1
if EdgeWebBrowser.WebViewCreated Then Exit For
bv_Sleep( 1 )
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 )
bv_QOut( "Open the URL." )
bv_QOut( "" )
pu_nEvent = 0
EdgeWebBrowser.Navigate( cUrl )
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
bv_Sleep( 1 )
Next
If pu_nEvent <> 1 Then
MsgBox "Navigate() fail !"
EdgeWebBrowser.CloseBrowserProcess
EdgeWebBrowser.CloseWebView
Set EdgeWebBrowser = Nothing
Set Document = Nothing
wscript.quit
End If
bv_QOut( "New msedgewebview2.exe running PID(s) after loading :" )
cPids = bv_GetAllPidForExeRun( "msedgewebview2.exe" )
bv_QOut( cPids )
bv_QOut( "" )
bv_QOut( "Manage cookies." )
' Thanks to Wila : https://forums.antwise.com/showthread.php?tid=147
If 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 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
bv_Sleep( 1 )
Next
bv_Sleep( 1 )
End If
bv_QOut( "Print to PDF." )
pu_nEvent = 0
EdgeWebBrowser.PrintToPdf pu_cPdf, ""
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
bv_Sleep( 1 )
Next
bv_QOut( "Get HTML source." )
pu_nEvent = 0
Document.RequestCurrentHtml()
For i = 1 to 60 Step 1
If pu_nEvent <> 0 Then Exit For
bv_Sleep( 1 )
Next
bv_QOut( "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
bv_QOut( "Close the browser and clear memory." )
bv_QOut( "" )
EdgeWebBrowser.CloseBrowserProcess
EdgeWebBrowser.CloseWebView
Set EdgeWebBrowser = Nothing
Set Document = Nothing
bv_Sleep( 1 ) ' Delay to close the browser.
bv_QOut( "New msedgewebview2.exe running PID(s) after close the avtiveX :" )
cPids = bv_GetAllPidForExeRun( "msedgewebview2.exe" )
bv_QOut( cPids )
bv_QOut( "" )
bv_QOut( "End of script." )
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
' Get a string with coma with the PIDs of an exe is running.
Function bv_GetAllPidForExeRun( cExe )
Dim cPids
Dim oPid
Dim oLocator
Dim oProcess
Dim oWMI
Set oLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set oWMI = oLocator.ConnectServer( ".", "root\cimv2" )
oWMI.Security_.ImpersonationLevel = 3
Set oProcess = oWMI.ExecQuery( "Select * from Win32_Process where Name = '" & cExe & "'" )
cPids = ""
For each oPid in oProcess
cPids = cPids & Cstr( oPid.Handle ) & ","
Next
Set oLocator = Nothing
Set oProcess = Nothing
Set oWMI = Nothing
bv_GetAllPidForExeRun = cPids
End Function
' Kill all exe by pids ( paramater string of pids with coma ).
Function bv_KillAllExeByPids( cPids )
Dim cReturn
Dim cPid
Dim cString
Dim i
cString = cPids
cReturn = ""
Do While ( True )
i = InStr( cString, "," )
If i = 0 Then Exit Do
cPid = Left( cString, i - 1 )
If Len( cPid ) = 0 Then Exit Do
cReturn = cReturn & bv_KillExeByPid( cPid )
cString = Right( cString, Len( cString ) - i )
If Len( cString ) = 0 Then Exit Do
Loop
bv_KillAllExeByPids = cReturn
End Function
' Kill an exe with his PID.
Function bv_KillExeByPid( cPid )
Dim cReturn
Dim oPid
Dim oLocator
Dim oProcess
Dim oWMI
Set oLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set oWMI = oLocator.ConnectServer( ".", "root\cimv2" )
oWMI.Security_.ImpersonationLevel = 3
Set oProcess = oWMI.ExecQuery( "Select * from Win32_Process where Handle = " & cPid )
cReturn = ""
For each oPid in oProcess
cReturn = cReturn & cPid & " "
On Error Resume Next
oPid.Terminate
If Err.Number <> 0 Then
cReturn = cReturn & "Not "
Err.Clear
End If
On Error GoTo 0
cReturn = cReturn & "Killed" & vbCrLf
Next
Set oLocator = Nothing
Set oProcess = Nothing
Set oWMI = Nothing
bv_KillExeByPid = cReturn
End Function
' 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
' Write a line in the console.
Sub bv_QOut( cText )
WScript.StdOut.WriteLine cText
End Sub
' Write character(s) in the console.
Sub bv_QQOut( cText )
WScript.StdOut.Write cText
End Sub
' Pause in script in second(s).
Sub bv_Sleep( n )
WScript.Sleep Int( n * 1000 )
End Sub
RE: i want msedgewebview2 process ID.. - wila - 2023-02-11
Hi Bernard,
Thanks for your answer.
Yes, that will work if there is one application hosting a WebView2 process. However if there are multiple applications using a webview2 control then you might be killing the process of another application. Something you'd probably want to prevent.
The solution provided in the private/preview version of AntView with BrowserProcessIDLong is passing the actual process ID as returned by the WebView2 control. I know how-to parse that manually from child processes via the Windows API, but that only makes sense if there's a problem with their implementation. I'm not aware of any actual issues with their solution, so best to pass on what the fine people at Microsoft gives us.
I'd expect BrowserProcessIDLong to also work for vbscript.
Note that the default stackoverflow answer for vb6 also uses long.
https://stackoverflow.com/questions/6190998/need-to-find-my-own-process-id-in-vb6
PS nice to see someone who knows their way in WMI queries. They can be very useful!
--
Wil
RE: i want msedgewebview2 process ID.. - Bernard Mouille - 2023-02-13
Hello Wil,
If you want, you can play with my WMI test code.
Regards,
Bernard.
Code: ' WMI.vbs
' Script to evaluate the Windows WMI ( CIM and Win32 classes ).
'
' This code is a basic sample.
'
' https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/cimwin32-wmi-providers
' https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-provider
option explicit
bv_LoadWithCScript()
' Parameter : active a class to edit ( not all class arent in this code ).
'Const classe = "CIM_Chassis" ' ok.
'Const classe = "CIM_Chip" ' ok.
'Const classe = "CIM_DesktopMonitor" ' ok.
'Const classe = "CIM_DMA" ' ok.
'Const classe = "CIM_Display" ' ok.
'Const classe = "CIM_LogicalDevice" ' ok.
'Const classe = "CIM_Memory" ' ok.
'Const classe = "CIM_MemoryCapacity" ' ok.
'Const classe = "CIM_MemoryCheck" ' ok.
'Const classe = "CIM_MemoryMappedIO" ' ok.
'Const classe = "CIM_MemoryOnCard" ' ok.
'Const classe = "CIM_NonVolatileStorage" ' ok.
'Const classe = "CIM_OSVersionCheck" ' ok.
'Const classe = "CIM_PhysicalMedia" ' ok.
'Const classe = "CIM_PhysicalElement" ' ok.
'Const classe = "CIM_PhysicalMemory" ' ok.
'Const classe = "CIM_Process" ' ok.
'Const classe = "CIM_Processor" ' ok.
'Const classe = "CIM_Product" ' ok.
'Const classe = "CIM_Setting" ' Error on << nItems = Items.count >>.
'Const classe = "CIM_Thread" ' ok.
'Const classe = "CIM_USBDevice" ' ok.
'Const classe = "CIM_VideoController" ' ok.
'Const classe = "Win32_1394Controller" ' ok.
'Const classe = "Win32_1394ControllerDevice" ' ok.
'Const classe = "Win32_AutochkSetting" ' ok.
'Const classe = "Win32_BaseBoard" ' ok.
'Const classe = "Win32_Battery" ' ok.
'Const classe = "Win32_BIOS" ' ok.
'Const classe = "Win32_Bus" ' ok.
'Const classe = "Win32_CacheMemory" ' ok.
'Const classe = "Win32_CDROMDrive" ' ok.
'Const classe = "Win32_CIMLogicalDeviceCIMDataFile" ' ok.
'Const classe = "Win32_ComputerSystem" ' Maybe a default : loop always.
'Const classe = "Win32_CurrentProbe" ' ok.
'Const classe = "Win32_DesktopMonitor" ' ok.
'Const classe = "Win32_DeviceChangeEvent" ' ok.
'Const classe = "Win32_DeviceMemoryAddress" ' ok.
'Const classe = "Win32_Directory" ' ok, long time.
'Const classe = "Win32_DiskDrive" ' ok.
'Const classe = "Win32_DiskPartition" ' ok.
'Const classe = "Win32_DisplayControllerConfiguration" ' ok.
'Const classe = "Win32_DMAChannel" ' ok.
'Const classe = "Win32_SystemEnclosure" ' ok.
'Const classe = "Win32_Fan" ' ok.
'Const classe = "Win32_FloppyController" ' ok.
'Const classe = "Win32_FloppyDrive" ' ok.
'Const classe = "Win32_HeatPipe" ' ok.
'Const classe = "Win32_IDEController" ' ok.
'Const classe = "Win32_IDEControllerDevice" ' ok.
'Const classe = "Win32_InfraredDevice" ' ok.
'Const classe = "Win32_IRQResource" ' ok.
'Const classe = "Win32_Keyboard" ' ok.
'Const classe = "Win32_LogicalDisk" ' ok.
'Const classe = "Win32_MotherboardDevice" ' ok.
'Const classe = "Win32_NetworkAdapter" ' ok.
'Const classe = "Win32_NetworkAdapterSetting" ' ok.
'Const classe = "Win32_NetworkAdapterConfiguration" ' ok.
'Const classe = "Win32_NetworkClient" ' ok.
'Const classe = "Win32_NetworkConnection" ' ok.
'Const classe = "Win32_NetworkLoginProfile" ' ok.
'Const classe = "Win32_NetworkProtocol" ' ok.
'Const classe = "Win32_NTEventLogFile" ' ok.
'Const classe = "Win32_NTLogEvent" ' ok, long time.
'Const classe = "Win32_NTLogEventLog" ' Long time.
'Const classe = "Win32_NTLogEventComputer" ' Long time.
'Const classe = "Win32_NTLogEventUser" ' Long time.
'Const classe = "Win32_OperatingSystem" ' ok.
'Const classe = "Win32_PerfFormattedData_TCPIP_NetworkInterface" ' ok.
Const classe = "Win32_Printer" ' ok.
'Const classe = "Win32_PrinterDriver" ' ok.
'Const classe = "Win32_Process" ' ok.
'Const classe = "Win32_Processor" ' ok.
'Const classe = "Win32_Refrigeration" ' ok.
'Const classe = "Win32_Service" ' ok.
'Const classe = "Win32_TemperatureProbe" ' ok.
'Const classe = "Win32_UserAccount" ' ok.
Const ForWriting = 2
Const TristateTrue = -1
Public pu_cOut : pu_cOut = bv_DirBase() & "\_Result.txt" ' TXT output file created.
Dim a
Dim cLine
Dim cType
Dim i
Dim Item
Dim Items
Dim Method
Dim n
Dim nItems
Dim oFile
Dim oFso
Dim oLocator
Dim oWMI
Dim Propertie
bv_fErase( pu_cOut )
Set oFso = CreateObject( "Scripting.FileSystemObject" )
Set oFile = oFso.OpenTextFile( pu_cOut, ForWriting, True, TristateTrue )
QOutWrite "WMI class selected : " & classe, oFile
QOutWrite "", oFile
Set oLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set oWMI = oLocator.ConnectServer( ".", "root\cimv2" )
Set Items = oWMI.ExecQuery( "Select * from " & classe )
nItems = Items.count
QOutWrite "Items count : " & CStr( nItems ), oFile
QOutWrite "", oFile
If nItems < 1 Then
QOutWrite "No item for class : " & classe, oFile
Else
i = 0
For Each Item in Items
i = i + 1
' Write the method(s).
If i = 1 Then
QOutWrite "Method(s) : " & Cstr( Item.Methods_.Count ), oFile
QOutWrite "", oFile
For Each Method in Item.Methods_
QOutWrite Method.Name & "()", oFile
Next
QOutWrite "", oFile
End If
bv_QOut( "Item " & Cstr( i ) & " / " & Cstr( nItems ) )
oFile.WriteLine( String( 70, "-" ) & " " + CStr( i ) & " / " & Cstr( nItems ) )
oFile.WriteLine( "" )
' Get the max lenght of the properties names.
n = 1
For Each Propertie in Item.Properties_
If Len( Propertie.Name ) > n Then
n = Len( Propertie.Name )
End If
Next
n = n + 1
' Write the properties.
For Each Propertie in Item.Properties_
cType = TypeName( Propertie.Value )
cLine = bv_Padr( cType, 11, " " ) & "- "
cLine = cLine & bv_Padr( Propertie.Name, n, "." ) & " "
If cType = "String" Then
cLine = cLine & Propertie.Value
ElseIf cType = "Null" Then
cLine = cLine
ElseIf cType = "Variant()" Then
cLine = cLine & "Array( " & CStr( UBound( Propertie.Value ) ) & " )" & vbCrLf
For a = LBound( Propertie.Value ) to UBound( Propertie.Value ) Step 1
cType = TypeName( Propertie.Value( a ) )
cLine = cLine & bv_Padl( Cstr( a ), 10, " " ) & " . "
cLine = cLine & bv_Padr( cType, 11, " " ) & ". "
If cType = "String" Then
cLine = cLine & Propertie.Value( a )
ElseIf cType = "Null" Then
cLine = cLine
ElseIf cType = "Variant()" Then
cLine = cLine & "Array( " & CStr( UBound( Propertie.Value( a ) ) ) & " )"
Else
cLine = cLine & CStr( Propertie.Value( a ) )
End If
If a < UBound( Propertie.Value ) Then
cLine = cLine & vbCrLf
End If
Next
Else
cLine = cLine & CStr( Propertie.Value )
End If
oFile.WriteLine( cLine )
Next
oFile.WriteLine( "" )
Next
End If
oFile.Close
Set oFile = Nothing
Set oFso = Nothing
Set Item = Nothing
Set Propertie = Nothing
Set Method = Nothing
Set oLocator = Nothing
Set Items = Nothing
Set oWMI = Nothing
bv_Run pu_cOut, 1, False
bv_Wait()
WScript.Quit
' ***** 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
' Load with CScript if the script is loaded with VBScript to look the console.
Sub bv_LoadWithCScript()
If InStr( LCase( WScript.FullName ), "cscript.exe" ) = 0 Then
CreateObject( "WScript.Shell" ).Run "cscript.exe //NoLogo """ & WScript.ScriptFullName & ""
WScript.Quit
End If
End Sub
' Add character(s) at left of a string.
Function bv_Padl( cString_bv, nChars_bv, cChar_bv )
bv_Padl = String( nChars_bv - Len( cString_bv ), cChar_bv ) & cString_bv
End Function
' Add character(s) at right of a string.
Function bv_Padr( cString_bv, nChars_bv, cChar_bv )
bv_Padr = cString_bv & String( nChars_bv - Len( cString_bv ), cChar_bv )
End Function
' Write a line in the console.
Sub bv_QOut( cString_bv )
WScript.StdOut.WriteLine cString_bv
End Sub
' Write a line in the console and in a file.
Sub QOutWrite( cString_bv, oFile_bv )
WScript.StdOut.WriteLine cString_bv
oFile_bv.WriteLine( cString_bv )
End Sub
' Run with options.
Sub bv_Run( cRun_bv, cDisplay_bv, lStop_bv )
CreateObject( "WScript.Shell" ).Run cRun_bv, cDisplay_bv, lStop_bv
End Sub
' Wait and exit with press << Enter >>.
Sub bv_Wait()
Dim cString_bv
WScript.StdOut.WriteLine ""
WScript.StdOut.Write "Press << Enter >> to exit"
cString_bv = WScript.StdIn.ReadLine
End Sub
RE: i want msedgewebview2 process ID.. - wila - 2023-02-13
Thanks Bernard,
I'll give it a go later. I have used wmi scripts from other programming environments before.
Not everyone is aware about them.
Actually I was playing with your vbscript code.
It throws an error on my end and then it works, so I have something to chase down.
--
Wil
RE: i want msedgewebview2 process ID.. - Bernard Mouille - 2023-02-23
Hello Hys999,
In VBScript,
CLng( EdgeWebBrowser.Control.BrowserProcessID ) 'works.
Maybe it is usefull for you.
Regards,
Bernard.
RE: i want msedgewebview2 process ID.. - wila - 2023-02-23
Hi Bernard,
It looks like that you missed the solution I posted above.
Your solution does not work in VB6, it still triggers the error that was originally posted. I just tested that in VB6 to verify that it can't be used as a workaround. It would have been really nice if it worked.
However the following does work (needs the 1.1.270 release):
Code: Dim PID As Long
PID = EdgeWebBrowser.BrowserProcessIDLong
Debug.Print "PID = " & CStr(PID)
There's a new BrowserProcessIDLong property that was introduced as a solution for this problem.
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-14
Oh.. It's been a while since I've been busy, so I'm very grateful for the many support replies. However, I saw a case where AntView ran 1:n with msedgewebview2.exe as a non-1:1 matching thread and then disappeared.
So I'm looking for another way. Rather... before the msedgewebview2.exe file runs
The name I gave the file name of it. .
For example, in the form of main_webview.exe
can i run it?
if it is possible
I am running on my project main form (form1)
Keep [main_webview.exe]..
Countless numbers executed in subwindows (form2, form3...)
Kill msedgewebview2.exe all easily and cleanly
I wish I had.
I have antview running the main form (form1)
must never die. to prevent it...
Again, msedgewebview2.exe
I want to make it run by specifying the file name in antview.
I would appreciate it if you could let me know if it is possible.
RE: i want msedgewebview2 process ID.. - wila - 2023-03-14
Hi,
I don't think you can change the name of the running webview2 process.
You are right, like with the browser itself, there are many processes, each for a different purpose.
One thing you could explore is to see if setting a chrome flag helps, you can set these via the AdditionalBrowserArguments property.
There are many options, more than I can list here. See the links at the forementioned property, in particular the site that lists most flags: https://peter.sh/experiments/chromium-command-line-switches/
One flag there might help: --single-process
However.. I don't think you should do that and I do not think it is needed either.
Have a look at the WebView2 process model here: https://github.com/MicrosoftDocs/edge-developer/blob/main/microsoft-edge/webview2/concepts/process-model.md
As you can see there is only 1 Browser Process, the rest are helpers. Closing the Browser Process should notmally close the helpers as it is their parent process.
The confusion is that they all share the same name when you look at them from task manager.
Note that if a browser process fails that it normally triggers the OnProcessFailed event, which is also available from within AntView.
The following github discussion for a WPF implementation might also help understanding how things work.
https://github.com/MicrosoftEdge/WebView2Feedback/issues/799
Hope this helps,
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-15
Thank you for your reply. There are people like me. Heh
It is difficult to dispose cleanly because there are still a lot of running processes.
I'll refer you to it.
RE: i want msedgewebview2 process ID.. - wila - 2023-03-15
Hi,
If the above did not help and you want me to look into it, then please create a small reproducible example along with steps that I can use to reproduce the issue. You can then email that to support@antwise.com.
Another thing to keep in mind is that there can be other processes that use the WebView2 control and they will also have their own collection of msedgewebview2 processes running.
Personally I have found the Sysinternals Process Explorer better for diagnosing these kind of issues than the Windows Taskmanager.
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-15
Thank you for your interest.
I have 16 or so multiple webview processes on subform.
Thank you for your interest.Build and do what you want at the same time.
But some of my customers have bad system specs.
During processing, some webview processes
Suspension occurs due to lack of resources, etc.
Executed exe crashes, etc.. We face serious cases.
So I'm stuck in the middle of the process or
Or to force quit the old msedgewebview2
I used another background monitoring utility.
In addition, the PID that was investigated in advance in the main form was excluded.
Sometimes when you return to the main form after completing the work of the subform
The main site is dead white. My customers say that the site of the main form is
They complain to me because they are dead.
So in any case I
I want to protect the Main SITE from ever dying.
Again, because it is based on translation
Please note that there may be errors in grammar.
RE: i want msedgewebview2 process ID.. - wila - 2023-03-15
Hi,
There is only one msedgewebview2 browser process AFAIK.
You can however have multiple renderer processes. You should not have to close those by killing them manually.
Perhaps it would help if you can use suspend so that these processes use less memory when form2 is closed? That's currently not exposed, but I can add it if you think it helps.
Note that you would have to then handle suspended browsers and resume them on re-opening the form again.
If the main browser process crashes.. you certainly have a problem.
There can be several reasons for that, lack of resources is one, but bad GPU drivers is another one.
As a first step I would suggest to try and disable GPU hardware acceleration.
You can do so by setting environment variables "--ignore-gpu-blocklist --disable-gpu-driver-bug-workarounds" via the AdditionalBrowserArguments property.
The MS Edge browser will handle this by itself, but for WebView2 it is up to us to handle this with more grace.
Are you currently using the OnProcessFailed event? If not then do as it helps tracking when things go bad.
For customers having issues it might also help to turn on the logging feature so that you can get some more details.
See: https://doc.antview.dev/hs190.htm
There's 2 log levels that you can use.
--
Wil
RE: i want msedgewebview2 process ID.. - wila - 2023-03-15
Also note that when you manually kill msedgewebview2 processes - even excluding the main browser process id - you WILL end up killing the wrong processes still.
Even if you start a single WebView2 you will get like 5 different processes!
There's the main browser process, at least a single renderer process, a utility process, a GPU process, there can be one or more background processes etc...
If you want to close a WebView2 process then you should use the CloseWebView method, not kill a background process.
The CloseBrowserProcess should only be used if you have no WebView2 processes running anymore. Normally you should not need it as the Browser Process is closed when your application exits.
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-15
yes i have been very helpful
I had such a problem because 16 processes are behaving erratically from time to time. Fixed some remaining zombies when abnormally interrupted.
But I solved it with a trick first.
Because it executed both form2 modally
before returning to the main ,
Kill all garbage processes.
I solved it by reopening the main window. he
It may be a bit unusual, but
So far, that's the best way for me.
Thank you very much for your detailed help.
RE: i want msedgewebview2 process ID.. - wila - 2023-03-16
Yes, that might also work.
Recreating the webview2 control dynamically on returning to form1 can help in your case.
I would still wonder if you can't prevent the crash from happening, but having a solution for your customer(s) now is a good start and might be sufficient.
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-16
I think.. if possible
If you can make [restart] method in Antview control
Any help would be great.
If your browser is dead white
Completely initialize Antview + enable it to be reactivated
If you provide a way, you don't have to bother reopening the main window.
I want to easily restore the browser to its original state in case of emergency.
It may be our greed, but we can overcome various situations.
RE: i want msedgewebview2 process ID.. - wila - 2023-03-16
The restart you are talking about is basically a:
- CloseWebView, followed by
- CreateWebView
But if your browser has crashed (does OnProcessFailed trigger?) then you might need some additional cleanup.
That additional cleanup will take time though as now the background processes all have to be started up from scratch for the out of process control.
In that case you would do something like:
- CloseWebView
- CloseBrowserProcess
- ... wait until the BrowserProcessIDLong property returns 0
- CreateWebView
No restart command needed I think as it would do the above.
A completely different approach might be to use VB6 CreateObject method to create the WebView2 control instead of creating it in the VB6 designer.
Clearly I don't know all the background and the things you need, but I would still try and see if you can help prevent the crash (like disabling the GPU acceleration bit).
--
Wil
RE: i want msedgewebview2 process ID.. - hys999 - 2023-03-17
oh. .thank you so much
As of now, the test results
It works satisfactorily.
I really appreciate you.
I already have a custom control form
I made my own browser component.
In it I added the below command.
======================
Public Sub reSTART()
On Error Resume Next
Dim startTime As Single, xtime As Single
Antview1.CloseWebView
Antview1.CloseBrowserProcess
startTime = Timer
Do
xtime = Abs(Timer - startTime)
DoEvents
If xtime > 4 Then
Exit Do
Else
If Antview1.BrowserProcessIDLong < 1 Then Exit Do
End If
Loop
Antview1.CreateWebView
End Sub
=================================
But I have a question.
When I didn't close it manually... i.e.
If your browser crashes or dies
Antview1.BrowserProcessIDLong value
If it is read, does the result return a value of 0?
I check if the browser is dead and
Check only if dead. I want to restart...
RE: i want msedgewebview2 process ID.. - wila - 2023-03-17
Hi,
Good question.
I don't know if the BrowserProcessIDLong property is set to 0 when the browser crashes.
Right now I'm passing on this property from Microsoft: BrowserProcessID
Their documentation doesn't have that kind of detail.
But when the browser crashes, the OnProcessFailed event should trigger and you can use that to identify if the browser crashed. The OnProcessFailed event basically wraps CoreWebView2.ProcessFailed.
What I would do is create a property on your form, say a boolean: BrowserCrashed that you set to False on CreateWebView.
Then in event OnProcessFailed you set BrowserCrashed to True.
In your restart logic you can then use the BrowserCrashed property to see what action to take.
Hope this helps,
--
Wil
|