0

The question refers to the answer of longvh (Apr 25 at 4:27) to the question how to automate Edge Browser using VBA without downloading Selenium. I mean method 2 which seems to be the best. The method works, the code works, but extra and unnecessary windows appear:

  • identity_helper.exe (black window). After a while it disappears by itself.
  • msedge.exe (black window).

Is it possible to make a code hiding these windows?

Thank you in advance: PJ

1 Answers1

0

This is ugly solution, but ad hoc I've "solved" it in my own way:

Public Declare PtrSafe Function ShowWindow Lib "user32" (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long

Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassname As String, ByVal lpWindowName As String) As Long

Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassname As String, ByVal nMaxCount As Long) As Long


Public Sub looking_for_windows()

Dim strComputer As String
    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", , 48)


    'All open processes
    For Each objItem In colItems
        
        If objItem.ExecutablePath Like "*msedge.exe" Or objItem.Name Like "*msedge.exe" Then
        Call hide_my_window(objItem.ExecutablePath)
        End If
        
        If objItem.ExecutablePath Like "*identity_helper.exe" Or objItem.Name Like "*identity_helper.exe" Then
        Call hide_my_window(objItem.ExecutablePath)
        
       'I can't kill it, so leave
        'Call Shell("TaskKill /F /PID " & objItem.ProcessId, vbHide)
        'Call Shell("TaskKill /IM ""identity_helper.exe"" /F", vbHide)
        End If
        
    Next
End Sub


Private Sub hide_my_window(ByVal Ret)

If IsNull(Ret) = False Then
Dim WinWnd As LongPtr, RetVal As Long, lpClassname As String

 WinWnd = FindWindow(vbNullString, Ret)
 ShowWindow WinWnd, SW_FORCEMINIMIZE
 If Ret Like "*identity_helper.exe" Then
 ShowWindow WinWnd, SW_HIDE
 End If

End If
 
End Sub

(I've also been discussing it in comments on: https://www.codeproject.com/Tips/5307593/Automate-Chrome-Edge-using-VBA?msg=5879883#xx5879883xx)