2

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
0

2 Answers 2

3

The problem might be that the {app} contains spaces (Program Files?), while {tmp} does not. Your syntax does not handle paths with spaces correctly.

This is the correct syntax:

[Run]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\Certs.ps1"" ""{commonappdata}""";\ 
  Flags: runhidden

[UninstallRun]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File ""{app}\UninstallCerts.ps1"" ""{app}"""; \
  Flags: runhidden; RunOnceId: "MyAppId"

The """"" you have in your syntax is noop. It passes "" to PowerShell, which treats is as nothing.

Sign up to request clarification or add additional context in comments.

Comments

0

Inno setup dont Understand system32 but sysnative. use parameter for [run] et [Uninstalrun]

Filename: "C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe";
Parameters: "-ExecutionPolicy Bypass -File ""{app}\UninstallCerts.ps1"" ""{app}""";
Flags: runhidden; RunOnceId: "MyAppId"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.