Start-Process failing once packaged as EXE

Tool: Visual Studio Code
Version: 1.68

Hi, I’ve created a tool to check and configure users BYOD device and the script works perfectly. Ideally we want this as an exe to distribute and when i package the ps1 using PowerShell Pro Tools the steps that use Start-Process fail, specifically the line

Start-Process -FilePath "changepk.exe" -ArgumentList "/ProductKey XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"

I’ve tried a combination of parameters such as

-Verb RunAs -WindowStyle Normal -Wait

When it runs i get the following error produced (outputting to console for testing)

Any ideas or pointers would be greatly appreciated.

As an update, converting the existing script using ps2exe to an exe runs without issue but I’d much rather produce this through PS Pro Tools.

Appreciate any suggestions as to why start-process “Changepk.exe” fails but start-process “notepad.exe” works?

Can anyone else replicate the issue?

This could be a platform issue. By default, pro tools compiles as x86. You can try switching it to x64 to see if that makes a difference. notepad exists in both syswow64 and system32 so that might be why that works.

@BenDrew, have you tried specifying the full path of changepk.exe (e.g. ‘c:\temp\changepk.exe’)? I assume that notepad.exe would be easier for the application to find since it is in the PATH but changepk.exe would not be in the path.

My advice would be to rule out pathing issues by hard-coding the path to changepk.exe file (for now). Once the cause is identified then it should be easier to replace the hard-coded path with something better.

Yeah, I tried c:\windows\system32\changepk.exe as this is where Microsoft put the exe, which is another reason why I’m confused that its not working. if I change the exe to notepad (which, as we know is also in system32) that starts with no error.

I did also try using the $env:systemroot\system32\changepk.exe with no improvement. I’m certain its connected with the changepk.exe which support from MS is sketchy at best.

I’m getting around it atm using ps2exe but obviously would prefer to use Pro Tools. I’ve yet to try @adam suggestion, but I’ll need to figure out how to compile as x64 rather than the native x86!

Thanks for the help and suggestions!

@adam, setting Platform = 'x64' in the package.psd1 seems to have sorted the issue and changepk.exe now launches and changes the Windows product key as expected.

Thanks both for the support, wouldn’t have thought of x86/x64 platform as being a cause!

2 Likes