Prerequisites
PSAppDeployToolkit version
4.1.4 dev
Describe the bug
Running the following command, it works on first run then crashes when run a 2nd time (which seems to be when it's parsing the '1.0' found in HKCU):
Set-ADTActiveSetup -StubExePath 'C:\Windows\System32\cmd.exe' -Arguments '/c exit 0' -Version '1.0' -Verbose
[2025-09-03T14:25:10.6152765+01:00] [Execution] [Set-ADTActiveSetup] [Error] :: Failed to set Active Setup registry entry.
Error Record:
-------------
Message : Exception calling "TryParse" with "2" argument(s): "Cannot convert value "10" to type "System.Version". Error: "Version string portion was too short or too long.""
InnerException : System.Management.Automation.PSInvalidCastException: Cannot convert value "10" to type "System.Version". Error: "Version string portion was too short or too long." ---> System.ArgumentException: Version string portion was too short or too long.
at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
at System.Version.TryParseVersion(String version, VersionResult& result)
at System.Version.Parse(String input)
--- End of inner exception stack trace ---
at System.Management.Automation.LanguagePrimitives.ConvertViaParseMethod.ConvertWithoutCulture(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at CallSite.Target(Closure , CallSite , Object )
at CallSite.Target(Closure , CallSite , Type , Object , PSReference )
FullyQualifiedErrorId : PSInvalidCastException,Set-ADTActiveSetup
ScriptStackTrace : at Test-ADTActiveSetup, C:\users\admin\Desktop\PSAppDeployToolkit\Public\Set-ADTActiveSetup.ps1: line 282
at Set-ADTActiveSetup<Process>, C:\users\admin\Desktop\PSAppDeployToolkit\Public\Set-ADTActiveSetup.ps1: line 514
Furthermore, Windows native handling of comparing active setup versions does not work when dots are used:
https://helgeklein.com/blog/active-setup-explained/
Therefore I propose that we help the user here by converting user-supplied versions such as 1.0 to 1,0 before writing them to the registry, writing a warning as we do so.
I'm finding it hard to parse mentally how the version parsing is working in Set-ADTActiveSetup.ps1 (lines 282 & 289). But using -split '\D' is a good trick to extract the digits - e.g. split on everything that's not a digit, join with commas, remove leading/trailing commas and pad out to add ',0' if we're only left with a single number:
`$Version -split '\D' -join ',' -replace '^,+|,+$','' -replace '^\d+$','$0,0'
Steps to reproduce
Run this twice:
Set-ADTActiveSetup -StubExePath 'C:\Windows\System32\cmd.exe' -Arguments '/c exit 0' -Version '1.0' -Verbose
Environment data
Prerequisites
PSAppDeployToolkit version
4.1.4 dev
Describe the bug
Running the following command, it works on first run then crashes when run a 2nd time (which seems to be when it's parsing the '1.0' found in HKCU):
Furthermore, Windows native handling of comparing active setup versions does not work when dots are used:
https://helgeklein.com/blog/active-setup-explained/
Therefore I propose that we help the user here by converting user-supplied versions such as 1.0 to 1,0 before writing them to the registry, writing a warning as we do so.
I'm finding it hard to parse mentally how the version parsing is working in Set-ADTActiveSetup.ps1 (lines 282 & 289). But using
-split '\D'is a good trick to extract the digits - e.g. split on everything that's not a digit, join with commas, remove leading/trailing commas and pad out to add ',0' if we're only left with a single number:`$Version -split '\D' -join ',' -replace '^,+|,+$','' -replace '^\d+$','$0,0'
Steps to reproduce
Run this twice:
Environment data
🙃