Jump to content

AutoIt Snippets


Chimaera
 Share

Recommended Posts

On 1/14/2024 at 8:55 AM, ioa747 said:
; Title...........: ShellTrayRefresh.au3

 

I doubt this will work with hidden taskbar.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

  • 4 weeks later...

Get the binary type for exe / dll file.

;Coded by UEZ build 2024-04-08
#AutoIt3Wrapper_UseX64 = y
#include <WinAPIFiles.au3>
#include <WinAPIProc.au3>

Global $sFile = FileOpenDialog("Select a DLL file", "", "File (*.dll;*.exe)", $FD_FILEMUSTEXIST)
If @error Then Exit
MsgBox($MB_ICONINFORMATION, "File Binary Type", StringRegExpReplace($sFile, ".+\\(.+)", "$1") & " = " & _WinAPI_GetBinaryType2($sFile))

; #FUNCTION# ====================================================================================================================
; Author.........: UEZ
; Modified.......:
; ===============================================================================================================================
Func _WinAPI_GetBinaryType2($sFile)
    Local Const $hFile = _WinAPI_CreateFile($sFile, 2, 2)
    If Not $hFile Or @error Then Return SetError(1, 0, 0)
    Local Const $hMapping = _WinAPI_CreateFileMapping($hFile, 0, Null, $PAGE_READONLY, Null)
    If Not $hMapping Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(2, 0, 0)
    EndIf
    Local Const $pAddress = _WinAPI_MapViewOfFile($hMapping, 0, 0, $FILE_MAP_READ)
    If Not $pAddress Or @error Then __ReturnGBT2($hMapping, $hFile, 3)
    Local $aHeader = DllCall("Dbghelp.dll", "ptr", "ImageNtHeader", "ptr", $pAddress)
    If @error Or IsArray($aHeader) = 0 Then Return __ReturnGBT2($hMapping, $hFile, 4)
    Local $tIMAGE_NT_HEADERS = DllStructCreate("dword Signature;ptr FileHeader;ptr OptionalHeader;", $aHeader[0])
    If @error Or Not IsDllStruct($tIMAGE_NT_HEADERS) Then Return __ReturnGBT2($hMapping, $hFile, 5)
    Local $tIMAGE_FILE_HEADER = DllStructCreate("word Machine;word NumberOfSections;dword TimeDateStamp;dword PointerToSymbolTable;dword NumberOfSymbols;word SizeOfOptionalHeader;word Characteristics;", DllStructGetPtr($tIMAGE_NT_HEADERS) + 4)
    If @error Or Not IsDllStruct($tIMAGE_FILE_HEADER) Then Return __ReturnGBT2($hMapping, $hFile, 6)
    __ReturnGBT2($hMapping, $hFile, 0)
    Switch $tIMAGE_FILE_HEADER.Machine
        Case 0x014c
            Return "x86"
        Case 0x0200
            Return "Intel Itanium"
        Case 0x8664
            Return "x64"
        Case Else
            Return "Error"
    EndSwitch
EndFunc   ;==>_WinAPI_GetBinaryType2

Func __ReturnGBT2($hMapping, $hFile, $iError)
    _WinAPI_CloseHandle($hMapping)
    _WinAPI_CloseHandle($hFile)
    If $iError Then Return SetError($iError, 0, 0)
EndFunc   ;==>__ReturnGBT2

 

Edited by UEZ
small modifications

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 4 months later...
2 hours ago, Nine said:

Wonder how to have a progress in your window task bar, here you go

...
  Local $oTaskBar = TB_Init()
  $oTaskBar.SetThumbnailTooltip($hGUI, "1st line" & @CRLF & "2nd line")
...

would you post an example for each in the $tag ? ( that'd be super cool ) :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

6 hours ago, Nine said:

Wonder how to have a progress in your window task bar

Is that even a thing in Windows 11 anymore? I used to love those effects in Windows 7 (Ah the nostalgia)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Expanding on Nine's task bar adventures... The overlay icon and tooltip were the only other interesting task bar things to me, so I added those + examples

#include <GUIConstantsEx.au3>
#include <WinAPIIcons.au3> ; For _WinAPI_DestroyIcon
#include <WinAPIShellEx.au3> ; For _WinAPI_ShellExtractIcon

Global Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
Global Const $sIID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
Global Const $tagITaskbarList3 = _
    "HrInit hresult();" & _
    "AddTab hresult(hwnd);" & _
    "DeleteTab hresult(hwnd);" & _
    "ActivateTab hresult(hwnd);" & _
    "SetActiveAlt hresult(hwnd);" & _
    "MarkFullscreenWindow hresult(hwnd;boolean);" & _
    "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);"

Example()

Func Example()
  Local $hGUI = GUICreate("AutoIt v3", 400, 100)
  GUISetState()

  Local $oTaskBar = TB_Init()

  TB_ToolTip($oTaskBar, $hGUI, "Working...")

  ; Load an icon -- this is a blue refresh on Win11
  Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & "\shell32.dll", 238, 32, 32)
  TB_SetOverlayIcon($oTaskBar, $hGUI, $hIcon, "Blue refresh")

  For $i = 1 To 100
    TB_SetProgress($oTaskBar, $hGUI, $i, 100)
    Sleep(25)
  Next
  
  ; Destroy the old icon
  _WinAPI_DestroyIcon($hIcon)
  
  Local $hSecondIcon = _WinAPI_ShellExtractIcon(@SystemDir & "\shell32.dll", 300, 32, 32)
  TB_SetOverlayIcon($oTaskBar, $hGUI, $hSecondIcon, "Green checkmark")

  TB_Flash($oTaskBar, $hGUI, 4, 300)

  TB_ToolTip($oTaskBar, $hGUI, "Waiting for you to close the window")

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
  ; Clear the icon overlay
  TB_SetOverlayIcon($oTaskBar, $hGUI, Null)
  _WinAPI_DestroyIcon($hSecondIcon)

EndFunc   ;==>Example

Func TB_Init()
  Local $oTB = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $tagITaskbarList3)
  $oTB.HrInit()
  Return $oTB
EndFunc   ;==>TB_Init

Func TB_SetProgress(ByRef $oTB, $hWnd, $iCurrent, $iCompleted)
  $oTB.SetProgressValue($hWnd, $iCurrent, $iCompleted)
EndFunc   ;==>TB_SetProgress

Func TB_Flash(ByRef $oTB, $hWnd, $iTimes, $iDelay)
  For $i = 1 To $iTimes
    $oTB.SetProgressState($hWnd, 0)
    Sleep($iDelay)
    $oTB.SetProgressValue($hWnd, 100, 100)
    Sleep($iDelay)
  Next
  $oTB.SetProgressState($hWnd, 0)
EndFunc   ;==>TB_Flash

; These are icons added to your taskbar icon, showing status usually. Each window only gets 1. Set $hIcon to NULL to clear. 
; (Win11) Teams uses this to show your status (busy, free, inactive) and Outlook uses it to show if you have an unread email
Func TB_SetOverlayIcon(ByRef $oTB, $hWnd, $hIcon, $sAltText = "")
    $oTB.SetOverlayIcon($hWnd, $hIcon, $sAltText)
EndFunc   ;==>TB_SetOverlayIcon

; Depending on settings and version, this may be difficult to see. On Win11 with taskbar previews, it is only visible after hovering over the preview window.
Func TB_ToolTip(ByRef $oTB, $hWnd, $sTooltip)
    $oTB.SetThumbnailTooltip($hWnd, $sTooltip)
EndFunc   ;==>TB_ToolTip

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

If you want to modify the appearance of any blocking functions, here one way :

#include <WindowsConstants.au3>
#include <WinAPISys.au3>

OnAutoItExitRegister(OnAutoItExit)

Global $hForm = GUICreate('Example')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), WM_SHELLHOOK)
_WinAPI_RegisterShellHookWindow($hForm)

MsgBox($MB_OK, "MsgBox", "Message")
InputBox("InputBox", "Prompt")
FileOpenDialog("FileOpenDialog", @ScriptDir, "au3 (*.au3)")

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
  If $wParam <> $HSHELL_WINDOWCREATED Then Return
  Switch WinGetTitle($lParam)
    Case "MsgBox"
      ControlSetText($lParam, "", "Static1", "Cool Stuff")
      ControlSetText($lParam, "", "Button1", "New")
    Case "InputBox"
      Local $hCtrl = ControlGetHandle($lParam, "", "Edit1")
      Local $hFont = _WinAPI_CreateFont(16, 0, 0, 0, 600)
      _SendMessage($hCtrl, $WM_SETFONT, $hFont, False)
      _WinAPI_DeleteObject($hFont)
    Case "FileOpenDialog"
      ControlHide($lParam, "", "Button2")
  EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Func OnAutoItExit()
  _WinAPI_DeregisterShellHookWindow($hForm)
EndFunc   ;==>OnAutoItExit

 

Link to comment
Share on other sites

  • 1 month later...
ConsoleWrite('--- ProcessStartDate: ' & ProcessStartDate('SciTE.exe') & @CRLF) ; --- ProcessStartDate: 2024/10/28 09:45:50
Func ProcessStartDate($sProcessOrPID, $iRet_tSYSTEMTIME = 0, $iLocalTime = 0)
    Local $aFT, $tFT, $tST, $iID = ProcessExists($sProcessOrPID)
    If $iID Then ; https://www.autoitscript.com/forum/index.php?showtopic=139260&view=findpost&p=1538034
        $aFT = _WinAPI_GetProcessTimes($iID)
        If @error Or UBound($aFT) <> 3 Then Return SetError(@error, _WinAPI_GetLastError(), "GetProcessTimes FAILED")
        $tST = _Date_Time_FileTimeToSystemTime($iLocalTime ? _Date_Time_FileTimeToLocalFileTime($aFT[0]) : $aFT[0])
        If $iRet_tSYSTEMTIME Then Return $tST
        Return _Date_Time_SystemTimeToDateTimeStr($tST, 1)
    EndIf
    Return SetError(11, 0, "Process does not exist")
EndFunc   ;==>ProcessStartDate

I have a bunch of RDP running and wanted to identify which is which and thought of the Process date and PID, to know that the given process was from X connection because when it disconnects the popup window does not have any info. in regards to what disconnected ... , am working on it. And thought that the function was a good snippet to share.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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...