My installer runs a PowerShell script to create certificates upon installation. In the [Files] section, I copy the two PowerShell scripts (one to install, one to uninstall):
[Files]
Source: "MyApp\Certs.ps1"; DestDir: "{tmp}\Neogen"; Flags: ignoreversion; \
Permissions: everyone-full
Source: "MyApp\UninstallCerts.ps1"; DestDir: "{app}"; Flags: ignoreversion; \
Permissions: everyone-full
The script to install the certificates uses a temp directory, and the uninstall script uses the app directory, which typically puts it into the C:\Program Files (x86)\MyApp folder. I can confirm that the uninstall script is being put into the correct folder.
When I uninstall the application, the certificates are not being uninstalled. The script looks like this:
Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.FriendlyName -match 'MyCert' } | Remove-Item
Get-ChildItem Cert:\LocalMachine\Root | Where-Object { $_.FriendlyName -match 'MyCert' } | Remove-Item
If I open a PowerShell window with administrator permissions and go to the C:\Program Files (x86)\MyApp folder to manually run the script, the script does work – the certificates are removed. It's just running the uninstall process from the Add / Remove program window where it fails.
My uninstall code in Inno Setup looks like this:
[UninstallRun]
Filename: "powershell.exe"; \
Parameters: "-ExecutionPolicy Bypass -File """"{app}\UninstallCerts.ps1 ""{app}"" """""; \
Flags: runhidden; RunOnceId: "MyAppId"
What am I missing when trying to run this PowerShell script when uninstalling?
Here is the syntax for how the certificate creation script (which does run successfully) is executed:
[Run]
Filename: "powershell.exe"; \
Parameters: "-ExecutionPolicy Bypass -File """"{tmp}\Certs.ps1 ""{commonappdata}"" """""; \
Flags: runhidden