Search code examples
nsiswindows-firewall

Add NSIS firewall exception for both private and public profiles


I want to add my application to windows firewall excpetion list. I am using NSIS Simple Firewall Plugin and doing following.

SimpleFC::AddApplication "${PRODUCT_NAME}" "$INSTDIR/${PRODUCT_NAME}.exe" 3 2 "" 1
Pop $0 ; return error(1)/success(0)

My app is getting added successfully to the firewall exception list but the problem is I want to add the exception for both public and private network profiles like below: enter image description here

But there is no option for same in the mentioned plugin, and the currently active profile (either public or private) gets selected by default.

I have explored other nsis firewall plugins but none of them has this feature. Can someone tell me the way forward? I may consider writing a custom plugin for the same.

But I am just wondering, is it achievabe or is there any fundamental blocker?

Although, you can always select both checkboxes manually.


Solution

  • I was never able to get any of the NSIS Firewall plugins to work correctly for me. I ended up simply shelling out to netsh on my target system:

    In the install section:

    ExecWait 'netsh advfirewall firewall add rule name=MyProg dir=in action=allow program="$INSTDIR\MyProg.exe" enable=yes profile=public,private'
    

    In the uninstall section:

    ExecWait 'netsh advfirewall firewall delete rule name=MyProg'