0

I'm working on creating a NSIS installer for our new VPN we will be getting in around a month. I have it calling a PowerShell script to create the connection without issue. However, removing the VPN connection is not working with the same method. Below is all my code for the uninstall

Section Uninstall ExpandEnvStrings $0 "%COMSPEC%" ExecShell "" '"$0"' "/C powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File .\DeleteVPNConnection.ps1 -connectionName ${VPN_NAME} " SW_HIDE Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\CreateVPNConnection.ps1" Delete "$INSTDIR\DeleteVPNConnection.ps1" RMDir /r "$INSTDIR" DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" SetAutoClose true SectionEnd 

Does anyone have any ideas why the uninstall script isn't working (and I have tried removing the connectionName parameter as well, same issue).

1
  • You are specifying .\ for the script's path. What is the current directory when the ExecShell runs? Commented Jan 11, 2018 at 23:04

1 Answer 1

3

There are two issues with your code:

  • You are specifying a relative .ps file path.
  • ExecShell does not wait so the .ps file might get deleted too early.

If you are using NSIS 3.02 you can use ExecShellWait:

ExpandEnvStrings $0 "%COMSPEC%" ExecShellWait "" '"$0"' '/C powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File "$InstDir\DeleteVPNConnection.ps1" -connectionName ${VPN_NAME}' SW_HIDE 

If you are using a older NSIS version then you must use ExecWait (does not hide the console window) or the nsExec plug-in.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.