Add context menu to Windows 10 to add firewall rule (elevated)...


  1. Posts : 7
    Windows 10 Home 64bit
       #1

    Add context menu to Windows 10 to add firewall rule (elevated)...


    I'm trying to achieve what was trivial in Windows 7 using the following registry entries:

    [HKEY_CLASSES_ROOT\exefile\shell\Add to Firewall\command]
    @="netsh advfirewall firewall add rule name=\"%1\" dir=out action=block program=\"%1\""

    [HKEY_CLASSES_ROOT\exefile\shell\Remove from Firewall\command]
    @="netsh advfirewall firewall delete rule name=\"%1\""


    Everything seems fine except that no rule is added.

    Apparently I need admin privileges which I have (Administrator account is active), but Windows ignores this. I can add a rule with no issues, if I run the netsh-command in an elevated command prompt.

    I need to run the commands without Windows asking for a password (the "runas /Administrator 'command'" will ask for the password).

    I read somewhere that "For a context menu command to be executed As Administrator(Elevated) you have to put the command under the special verb RunAs like:[HKEY_CURRENT_USER\Software\Classes\Directory\shell\runas\command]".

    How do the keys need to look so that the command will work as in Windows 7?

    Thanks,
    /Søren
      My Computer


  2. Posts : 21,421
    19044.1586 - 21H2 Pro x64
       #2

    Hello and welcome to TF ,
    You may find something useful here, though they use powershell in some places:

    Download Windows Firewall Context Menu for Windows 10

    Block/Unblock exe in Windows Firewall using right-click menu

    Make a backup first with Backup and Restore with Macrium Reflect
      My Computer


  3. Posts : 21,421
    19044.1586 - 21H2 Pro x64
       #3

    The link I meant to post was Add Windows Firewall Context Menu in Windows 10 which leads to the second one I did post.
      My Computer


  4. Posts : 7
    Windows 10 Home 64bit
    Thread Starter
       #4

    steve108 said:
    Hello and welcome to TF ,
    You may find something useful here, though they use powershell in some places:

    Download Windows Firewall Context Menu for Windows 10

    Block/Unblock exe in Windows Firewall using right-click menu

    Make a backup first with Backup and Restore with Macrium Reflect
    Thanks Steve!

    I ended up using this one, as it came closest to my original way of doing it. Yes, Powershell is not optimal but it gets the job done :)=

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall]
    @=""
    "MUIVerb"="Windows Defender Firewall"
    "icon"="%SYSTEMROOT%\\system32\\FirewallControlPanel.dll,0"
    "subcommands"=""

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell]
    @=""

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Block]
    @=""
    "MUIVerb"="Føj til Firewall"
    "icon"="%SYSTEMROOT%\\system32\\FirewallControlPanel.dll,1"

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Block\command]
    @="powershell -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"New-NetFirewallRule -DisplayName ([System.IO.Path]::GetFilenameWithoutExtension('%1')) -Name '%1' -Enabled True -Direction Outbound -Action Block -Program '%1'`\\\"\\\"\""

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Remove]
    @=""
    "MUIVerb"="Fjern fra Firewall"
    "icon"="%SYSTEMROOT%\\system32\\FirewallControlPanel.dll,2"

    [HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Remove\command]
    @="powershell -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"Remove-NetFirewallRule -Name '%1'`\\\"\\\"\""


    I find it a bit odd though that you can't use CMD in any way without having to struggle with elevated privileges. Maybe somebody else knows a way...?

    Thanks,
    Søren
      My Computer


  5. Posts : 39
    Windows 10 1511
       #5

    Søren, the reason it worked on Win7 is that you had UAC inactive and thus anything ran with full administrative powers, including explorer and its context menu. So with Win10, after turning off UAC it would just work.
      My Computer


  6. Posts : 7
    Windows 10 Home 64bit
    Thread Starter
       #6

    Comport Colin said:
    Søren, the reason it worked on Win7 is that you had UAC inactive and thus anything ran with full administrative powers, including explorer and its context menu. So with Win10, after turning off UAC it would just work.
    It doesn't work in Win10 with UAC deactivated. Like you said, it worked in Win7 with UAC disabled, but not in Win10.

    Win10 still wants me to login to the Admin account - because in Win10 apparently you need admin powers to add a rule to the firewall...

    Thanks,
      My Computer


  7. Posts : 39
    Windows 10 1511
       #7

    No, you just need to turn UAC off the right way, not using the lever but secpol.msc (or a regfile) as shown here, followed by a restart: Enable or Disable User Account Control (UAC) in Windows | Tutorials (tenforums.com)
    Just tried your 1st regfile on Win10 20H2 and it just works to add a rule that way.
      My Computer


  8. Posts : 7
    Windows 10 Home 64bit
    Thread Starter
       #8

    Comport Colin said:
    No, you just need to turn UAC off the right way, not using the lever but secpol.msc (or a regfile) as shown here, followed by a restart: Enable or Disable User Account Control (UAC) in Windows | Tutorials (tenforums.com)
    Just tried your 1st regfile on Win10 20H2 and it just works to add a rule that way.
    Hey! That worked!

    Thanks man, I just thought UAC was off when the lever was at the bottom - that was enough in Win7 but Win10 needed the regfile.

    Thanks - using the old school batch instead of Powershell then...
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:36.
Find Us




Windows 10 Forums