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

takumi harayama 1 Reputation point
2022-04-05T10:51:39.437+00:00

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,767 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,391 Reputation points
    2022-04-12T12:26:13.557+00:00

    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