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