Jump to content

Changing icon of "running" Chrome webdriver.


Recommended Posts

I have automated 3 websites using Autoit and the webdriver (Chrome).
T
he Chrome instance started by the Chrome webdriver always shows the Chrome icon.

This get a little comfusing when you already have several Chrome instances openend and you add some webdriver pages.

So. is there a way to assign other icons to the Chromedriver instances or show the fav.ico of the site as an icon for these Chrome web driver instances ?
(I have done several searches, but I only get answers were people wan't to change tie Chrome shortcut icons 😁)

BTW, I am not looking to change the icon of the Autoit executables I have created, but the icon the Chromedriver is using when running.

Link to comment
Share on other sites

Did that, console is hidden, but I still don't see a chromedriver.exe icon.

As a re-read it, Jemboy what icon are you referring too? In tray, taskbar or on the chrome window? Maybe share a screenshot.

 

Edited by KaFu
Link to comment
Share on other sites

@Danp2  No headless is not an option. My users need to interact with the websites 😉 
 

@KaFuThis is an issue I Google every couple of months to see if I can find a lead or solution. WM_SetICON looks promising, I gonna search in that direction to!😀

 

Link to comment
Share on other sites

Maybe this old thing could work ...

#include <WinAPI.au3>

; $hwnd = window handle
; $file = icon path

Func _WinSetIcon($hwnd, $file, $index = 0)
    Local $tIcons = DllStructCreate("ptr Data")
    DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $file, "int", $index, "struct*", 0, "struct*", $tIcons, "uint", 1)
    If @error Then Return SetError(1, 0, 0)
    Local $hicon = DllStructGetData($tIcons, "Data")
   _SendMessage($hwnd, 0x0080, 1, $hicon ) ;$WM_SETICON = 0x0080
   _WinAPI_DestroyIcon($hicon)
EndFunc

 

Link to comment
Share on other sites

Tried something similar, it sadly only changes the icon on the window (and not even for chrome.exe), not in the taskbar.

#include <WinAPIShellEx.au3>
run("Notepad.exe")
Sleep(500)

$hWnd_Notepad = WinGetHandle("[CLASS:Notepad]")

_SendMessage($hWnd_Notepad, 0x0080, 0, _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 15, 32, 32))
_SendMessage($hWnd_Notepad, 0x0080, 1, _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 15, 32, 32))

I guess it's more something in the direction of ITaskBarList.

In HMW I use ReadProcessMemory from the main "explorer.exe" process to extract TTBUTTON info for the systray. I think it might need something similar for the taskbar, even a WriteProcessMemory to set a new hIcon pointer.

Link to comment
Share on other sites

Na, seems no luck there.

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6582baa8-f5cd-4ce5-ae51-2f32490db9a5/windows-7-taskbar-the-undocumented-mstasklistwclass-?forum=windowsgeneraldevelopmentissues

Now in Windows 7 things changed. The last window in that chain - the actual taskbar - is not standard Toolbar (ToolbarWindow32) anymore. It is the window with MSTaskListWClass class now! This window does not react on any Toolbar messages like TB_BUTTONCOUNT or TB_HITTEST, etc. So it is impossible to interact with taskbar anymore!

Does anyone have any idea of how to access the Taskbar in Windows 7? Google gives nothing on MSTaskListWClass. Where can the documentation be found?

P.S.: The ITaskbarList interface is very poor, so it ain't an option :)

 
ITaskbarList still seems the way to go (somehow).
Link to comment
Share on other sites

Played around with ITaskbarList3, thought SetOverlayIcon might be a good way to mark the tab, sadly it doesn't work for me.

#include <WinAPIShellEx.au3>

Const $sCLSID_TaskbarList3 = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
Const $sIID_ITaskbarList3 = "{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}"
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-itaskbarlist3

Const $sTagITaskbarList3 = _
        "HrInit long();" & _
        "AddTab long(hwnd);" & _
        "DeleteTab long(hwnd);" & _
        "ActivateTab long(hwnd);" & _
        "SetActiveAlt long(hwnd);" & _
        "MarkFullscreenWindow long(hwnd;int);" & _
        "SetProgressValue long(hwnd;uint64;uint64);" & _
        "SetProgressState long(hwnd;int);" & _
        "RegisterTab long(hwnd;hwnd);" & _
        "UnregisterTab long(hwnd);" & _
        "SetTabOrder long(hwnd;hwnd);" & _
        "SetTabActive long(hwnd;hwnd;dword);" & _
        "ThumbBarAddButtons long(hwnd;uint;ptr);" & _
        "ThumbBarUpdateButtons long(hwnd;uint;ptr);" & _
        "ThumbBarSetImageList long(hwnd;ptr);" & _
        "SetOverlayIcon long(hwnd;ptr;wstr);" & _
        "SetThumbnailTooltip long(hwnd;wstr);" & _
        "SetThumbnailClip long(hwnd;ptr);"

Local $oMyError = ObjEvent("AutoIt.Error", "ErrFunc")

$oTaskbarList3 = ObjCreateInterface($sCLSID_TaskbarList3, $sIID_ITaskbarList3, $sTagITaskbarList3)

$oTaskbarList3.HrInit()
$iPid = Run("notepad.exe")
$hWnd = WinWait("[CLASS:Notepad]", "", 10)
If Not IsHWnd($hWnd) Then Exit 123

$hGUI = GUICreate("Test")
GUISetState()

$hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', -28, 16, 16)
$hCtrl = GUICtrlGetHandle(GUICtrlCreateIcon("", 10, 10, 16, 16))

#include <SendMessage.au3>
#include <StaticConstants.au3>

_SendMessage($hCtrl, $STM_SETIMAGE, 1, $hIcon)

$oTaskbarList3.SetOverlayIcon($hWnd, $hIcon, "")

$oTaskbarList3.SetOverlayIcon($hGUI, $hIcon, "")


_WinAPI_DestroyIcon($hIcon) ; It is the responsibility of the calling application to free hIcon when it is no longer needed. This can generally be done after you call SetOverlayIcon because the taskbar makes and uses its own copy of the icon.


; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate
$oTaskbarList3.SetProgressState($hWnd, 0x00000001)
Sleep(1000)

$oTaskbarList3.SetProgressState($hWnd, 0x00000000)

$oTaskbarList3.DeleteTab($hWnd)
Sleep(1000)

$oTaskbarList3.AddTab($hWnd)
Sleep(1000)

ProcessClose($iPid)


; This is a custom error handler
Func ErrFunc($oError)
    MsgBox($MB_OK, "We intercepted a COM Error !", _
            "Number: 0x" & Hex($oError.number, 8) & @CRLF & _
            "Description: " & $oError.windescription & _
            "At line: " & $oError.scriptline)
EndFunc   ;==>ErrFunc

 

Link to comment
Share on other sites

Got it working for my own process, there are two taskbar settings (use large icons, show badges) which must be enabled for it to work.

Sadly it does not work for other processes.

; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setoverlayicon
; This handle must belong to a calling process associated with the button's application and must be a valid HWND or the call is ignored.

 

#include <WinAPIShellEx.au3>
#include <WinAPIIcons.au3>
#include <Array.au3>

If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarBadges") <> 1 Then
    MsgBox(0, "Exit", "'Show badges on taskbar buttons' must be enabled in taskbar settings")
    Exit
EndIf

If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSmallIcons") = 1 Then
    MsgBox(0, "Exit", "'Use small taskbar buttons' must be disabled in taskbar settings")
    Exit
EndIf

; https://www.autohotkey.com/boards/viewtopic.php?f=74&t=67431&p=289834&hilit=SetOverlayIcon#p289834

Const $sCLSID_TaskbarList3 = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
Const $sIID_ITaskbarList3 = "{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}"
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-itaskbarlist3

Const $sTagITaskbarList3 = _
        "HrInit hresult();" & _
        "AddTab hresult(hwnd);" & _
        "DeleteTab hresult(hwnd);" & _
        "ActivateTab hresult(hwnd);" & _
        "SetActiveAlt hresult(hwnd);" & _
        "MarkFullscreenWindow hresult(hwnd;int);" & _
        "SetProgressValue hresult(hwnd;uint64;uint64);" & _
        "SetProgressState hresult(hwnd;int);" & _
        "RegisterTab hresult(hwnd;hwnd);" & _
        "UnregisterTab hresult(hwnd);" & _
        "SetTabOrder hresult(hwnd;hwnd);" & _
        "SetTabActive hresult(hwnd;hwnd;dword);" & _
        "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _
        "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _
        "ThumbBarSetImageList hresult(hwnd;ptr);" & _
        "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _
        "SetThumbnailTooltip hresult(hwnd;wstr);" & _
        "SetThumbnailClip hresult(hwnd;ptr);"

Local $oMyError = ObjEvent("AutoIt.Error", "_ErrFunc")

$oTaskbarList3 = ObjCreateInterface($sCLSID_TaskbarList3, $sIID_ITaskbarList3, $sTagITaskbarList3)

$oTaskbarList3.HrInit()
$iPid = Run("notepad.exe")
$hWnd = WinWait("[CLASS:Notepad]", "", 10)
If Not IsHWnd($hWnd) Then Exit 123

$hGui = GUICreate("Test")
GUISetState()

; $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', -28, 16, 16)
$hIcon = _WinAPI_LoadIconWithScaleDown(0, $IDI_SHIELD, 16, 16)
; $hIcon = _WinAPI_ExtractIcon("icon.ico", 0, True)

$hCtrl = GUICtrlGetHandle(GUICtrlCreateIcon("", 10, 10, 16, 16))

#include <SendMessage.au3>
#include <StaticConstants.au3>

; _ArrayDisplay(_WinAPI_GetIconInfo($hIcon))

_SendMessage($hCtrl, $STM_SETIMAGE, 1, $hIcon)

$oTaskbarList3.SetOverlayIcon($hWnd, $hIcon, "")
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setoverlayicon
; This handle must belong to a calling process associated with the button's application and must be a valid HWND or the call is ignored.

$oTaskbarList3.SetOverlayIcon($hGui, $hIcon, "")

Sleep(2000)

_WinAPI_DestroyIcon($hIcon) ; It is the responsibility of the calling application to free hIcon when it is no longer needed. This can generally be done after you call SetOverlayIcon because the taskbar makes and uses its own copy of the icon.


$oTaskbarList3.SetThumbnailTooltip($hGui, "ToolTip Test")

; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate
$oTaskbarList3.SetProgressState($hWnd, 0x00000001)
Sleep(1000)

$oTaskbarList3.SetProgressState($hWnd, 0x00000000)

$oTaskbarList3.DeleteTab($hWnd)
Sleep(1000)

$oTaskbarList3.AddTab($hWnd)
Sleep(1000)

ProcessClose($iPid)


Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Link to comment
Share on other sites

@KaFuI looked at your replies and this seemed more difficult then expected.
However your reply with the word "WM_ICON" triggered other searchs on that word.

Eventually I found a post from @Zedna see: 

This script was able to change the application icon for a Chrome.exe instance.
I have adjusted the "run" in Zedna's script, to start a Chrome instance and I was able to change the icon.

The only problem I have now is how to convert a PID to a handle so I can identify the process 100% accurately.
Otherwise, I probably can just use WinGetHandle.

Edited by Jemboy
Link to comment
Share on other sites

@NineTo mini script below shows the handle in the array.

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WinAPIProc.au3>

; Run Notepad with the window maximized.
Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

$aData = _WinAPI_EnumProcessWindows($iPID, True)
_ArrayDisplay($aData, '_WinAPI_EnumProcessWindows')

; Close the Notepad process using the PID returned by Run.
ProcessClose($iPID)

However when I replace Notepad with Chrome, the enumeration won't work anymore. @error =1.

 

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WinAPIProc.au3>

; Run Chrome with the window maximized.
Local $iPID = Run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", @SW_SHOWMAXIMIZED)

$aData = _WinAPI_EnumProcessWindows($iPID, True)
_ArrayDisplay($aData, '_WinAPI_EnumProcessWindows')

; Close the Chrome process using the PID returned by Run.
ProcessClose($iPID)

I have been looking for hours and I can;t seem to find a reason.
When running Chrome, the PID given, couldn't be found in the Tasklist either.
Maybe it is not working because Chrome is x86 and everything else is x64???? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...