How to create a rule that allows the program name without the full path.

takumi harayama 1 Reputation point

I need to create a rule with allows the program name without the full path because each software version has an EXE file opening some sockets like this:
C:\Program Files\aaaa\version001\TARGET.EXE
C:\Program Files\aaaa\version002\TARGET.EXE
C:\Program Files\aaaa\version003\TARGET.EXE
C:\Program Files\aaaa\version004\TARGET.EXE
C:\Program Files\aaaa\version005\TARGET.EXE
C:\Program Files\aaaa\version006\TARGET.EXE
: : :

Firstly, I created a script that adds all the EXE files to the new inbound rule one by one. But there are so many version folders today. Therefore, I need to simplify them and make one rule.

The question is how to make a rule that allows TARGET.EXE without full path. As an alternative solution, it is also nice that I can make a rule allows "C:\%Program Files%\aaaa*\TARGET.EXE" instead.

If I can add it, I will implement this in a script using HNetCfg object.

Windows 10 Security
Windows 10 Security
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
2,807 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,461 Reputation points

    Hello @takumi harayama

    May be a bit simplistic but I would workaround using a batch file that finds each file in the folders from the starting path C:\Program Files\aaaa\ then a DO to set the firewall rule.

    @ setlocal enableextensions   
    @ cd /d "C:\Program Files\aaaa\"  
    for /R %%a in (TARGET.EXE) do (  
    netsh advfirewall firewall add rule name="Blocked with Batchfile %%a" dir=out program="%%a" action=block  

    Hope this helps with your query,


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments