PowerShell, Scripting, Windows 7
comments 2

Programming Windows 7 taskbar using Windows API code pack and PowerShell

Windows® API Code Pack for Microsoft® .NET Framework provides a source code library that can be used to access some features of Windows 7 and Windows Vista from managed code. These Windows features are not available to developers today in the .NET Framework.

  • Windows 7 Taskbar
  • Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars
  • Windows Shell
  • Windows 7 Libraries
  • Windows Shell Search API support
  • Explorer Browser Control
  • A hierarchy of Shell Namespace entities
  • Windows Shell property system
  • Drag and Drop for Shell Objects
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls
  • Known Folders and non-file system containers
  • DirectX
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs
  • Windows Vista and Windows 7 Task Dialogs
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons
  • That is quite a bit. Being able to access these features from .NET makes it the best candidate for PowerShell too. When I came across this code pack, my first thought was to script something around Windows 7 Taskbar. I love the way IE 8 displays the progress bar embedded in to it’s taskbar button. So — in this post — I will explain how to create progress bar embedded in to an applications taskbar button.

    What you need?
    Download Windows API code pack and build the solution in Visual Studio
    – You will have Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll. Copy these two DLLs to a desired location

    How to use the API?
    Open PowerShell and load the assembly


    Create a TaskBarManager instance

    $TaskBarObject = [Microsoft.WindowsAPICodePack.TaskBar.TaskBarManager]::Instance

    Set the ProgressBar state


    This is not mandatory. However, it is important to understand the possible values. Here is what each of the progress bar states mean

    No Progress – No progress bar is displayed
    Indeterminate – The progress is indeterminate (marquee)
    Normal – Normal progress is displayed
    Error – An error occurred (red)
    Paused – The operation is paused (yellow)

    To set the progress bar value


    In the above method, 50 is the current progress value and 100 is the maximum possible value. Both parameters are mandatory.

    This is how it looks after all these steps.

    Progress Bar

    Progress Bar

    Now, its time for a real example. One of my most interesting work in PowerShell is the BITS PowerPack. It uses BITS file transfer cmdlets to do file trasfers and web downloads. I have a written a sample script using BITS cmdlets to show how we can program the taskbar progress bar to show the progress of BITS file transfer.

    First, download this script

     [download id=”17″ format=”4″]

    To run the sample
    Extract the same to a folder of your choice
    – Edit the script to point to the right path for the assemblies you built from Windows API Code Pack
    – Run the following commands and input the source and destination values for your download

    $argList = “-file D:\API\Start-Transfer.ps1″

    $argList += ” -noExit”

    Start-Process -FilePath “powerShell.exe” -ArgumentList $argList

    This is it. It will open a new window and you can see the progress bar moving. Enjoy the Windows 7 magic..!

    Filed under: PowerShell, Scripting, Windows 7


    Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.