TobiasPSP / Modules.PsoProgressButton

Easy access to taskbar button animation such as progress bar or colorization
MIT License
9 stars 0 forks source link

Fix for "Valid Window" issue #2

Open hl2guide opened 1 year ago

hl2guide commented 1 year ago

Please fix the valid window issue for Windows 10.

e.g.

PowerShell 7.3.5
PS C:\Users\Dean> Set-PsoProgressButtonValue -CurrentValue 50
MethodInvocationException: C:\Program Files\PowerShell\Modules\PsoProgressButton\1.0\Set-PsoProgressButtonValue.ps1:35
Line |
  35 |      [PsoShell.TaskbarManager]::Instance.SetProgressValue($CurrentValu …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "SetProgressValue" with "2" argument(s): "TaskbarManager: Valid Window Required"
PS C:\Users\Dean>

I've tried in Windows Terminal and a standard PowerShell console window.

TobiasPSP commented 1 year ago

It may not work with Powershell 7. did you try it with Windows PowerShell (5.1)?

hl2guide commented 1 year ago

In 5.1 I get:

PS C:\Users\Dean> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\Users\Dean> Set-PsoProgressButtonValue -CurrentValue 50
Set-PsoProgressButtonValue : The term 'Set-PsoProgressButtonValue' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ Set-PsoProgressButtonValue -CurrentValue 50
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-PsoProgressButtonValue:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I don't think it supports custom modules.

TobiasPSP commented 1 year ago

You need to install-module the module again from within windows powershell as both powershell versions use separate module folders.

TobiasPSP commented 1 year ago

So please simply run the install-module command from within windows powershell once again.

hl2guide commented 1 year ago

Okay, please consider adding support for PowerShell 7.3.5.

TobiasPSP commented 1 year ago

I hear you.

I believe this is a limitation of PowerShell 7 and its underlying .NET Core. In contrast to Windows PowerShell (which is based on the full .NET framework), the limited .NET core (and PowerShell 7) are unable to access niche-APIs (like the one used here which is highly specific to the Windows OS).

That said, .NET core is improved and expanded all the time. So if/once the APIs used here are ported to .NET core, this module will automatically start to work in PowerShell 7.

I am going to post a notice in the description.

On a side note, the issue encountered here is one of the reasons why most Windows-based enterprises continue to use Windows PowerShell for their production scripts. WPS isn’t deprecated. It’s just (unfortunately) not continued yet continues to provide the most complete support for Windows APIs.