Reputation: 779
I'm trying to figure out how to show progress on the taskbar. Via PowerShell.
As I understand it, I should use something like this:
$Progress = [System.Windows.Shell.TaskbarItemInfo]::New()
$Progress.ProgressState = 'Normal'
$Progress.ProgressValue = 0.3
But that does not work. What am I doing wrong? How to show progress on the taskbar? Thanks you
Upvotes: 5
Views: 1430
Reputation: 1
while your resoruce for the dll is no longer available, your answer (https://stackoverflow.com/a/59763114/18342953) worked properly fine using Microsoft.WindowsAPICodePack.Shell.dll shared with SourceTree 3.4.14. It no longer works with the one shipped with SourceTree 3.4.18.
The other answer (https://stackoverflow.com/a/59752877/18342953) opens another window instead of setting the TaskBarProgressColor+State of the current PowerShell window.
Is there either a way to make the XAML code work similar to your solution (so it sets the TaskBarProgressBarState+Color of the current PS window) or another source for a working dll?
Best regards, Rhino
Upvotes: 0
Reputation: 779
For those who are looking for an answer. As it turned out, the .NET Framework does not support show progress on the taskbar. Windows Forms also do not support this. It support on WPF now.
However, there is a solution. The solution was written by Ravikanth Chaganti. https://www.ravichaganti.com/blog/programming-windows-7-taskbar-using-windows-api-code-pack-and-powershell/. To do this, you need to download and install WindowsAPICodePack library (it was intended for Windows 7).:
Open PowerShell and load the assembly
[Reflection.Assembly]::LoadFrom(“D:\API\Microsoft.WindowsAPICodePack.Shell.Dll”)
Create a TaskBarManager instance
$TaskBarObject = [Microsoft.WindowsAPICodePack.TaskBar.TaskBarManager]::Instance
Set the ProgressBar state
$TaskBarObject.SetProgressState(“Normal”)
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
$TaskBarObject.SetProgressValue(50,100)
Upvotes: 7
Reputation: 3923
You can do this in WPF as using XAML creates a new window object, I don't think it's possible the way you're doing it.
# Add required assemblies
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration
# Setup the XAML
[xml]$script:xaml = '<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="MyWindow" Height="240" Width="320" Background="Gray">
<Window.TaskbarItemInfo>
<TaskbarItemInfo/>
</Window.TaskbarItemInfo>
<Grid>
<Image Name="image" Height="64" Width="64"/>
</Grid>
</Window>'
# Create the form and set variables
$script:window = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml))
$xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $window.FindName($_.Name) -Scope Script }
# This is the toolbar icon and description
$window.TaskbarItemInfo.Description = $window.Title
$window.TaskbarItemInfo.ProgressValue = 0.8
$window.TaskbarItemInfo.ProgressState = "Normal"
$window.ShowDialog()
Upvotes: 1