Firewall Context Menu
Posted: 06 Sep 2018 16:44
Goal
I need to add Block Firewall Context Menu For .exe Files.
Code
This code works perfectly fine when using it with filepath-that-doesnt-contain-space
If filepath containing spaces it will simply throw out this error. To debug, I added to previous code
Output
Twice
I am not sure why it ran the code twice. One theory I could come up with is that maybe it is trying add the folder with spaces in path as filename and also the filename to netsh?
While debugging using Echo I found out that it doesn't have "" inside the which i think it requires if the path or filename has spaces in it. I believe the "Qoutes" that are missing are causing this issue probably.
I have also tried escaping and adding double quotes. Still doesn't work.
Thank you all for your help, if you require more information or clarification please ask.
I need to add Block Firewall Context Menu For .exe Files.
Code
Code: Select all
Reg Add "HKEY_CLASSES_ROOT\exefile\Shell\Firewall\Command" /T Reg_SZ /D "Elevate.exe CMD.exe /Q /C For %%%%A In (\"%%1\") Do Netsh Advfirewall Firewall Add Rule Name=\"%%~nA\" Dir=Out Action=Block Program=\"%%1\""
If filepath containing spaces it will simply throw out this error. To debug, I added
Code: Select all
& pause
Output
Code: Select all
A specified value is not valid.
Usage: add rule name=<string>
dir=in|out
..
Press any key to continue. . .
Code: Select all
A specified value is not valid.
Usage: add rule name=<string>
dir=in|out
..
Press any key to continue. . .
While debugging using Echo I found out that it doesn't have "" inside the
Code: Select all
Netsh Rule Name="" and Program=""
I have also tried escaping and adding double quotes. Still doesn't work.
Code: Select all
Reg Add "HKEY_CLASSES_ROOT\exefile\Shell\Firewall\Command" /T Reg_SZ /D "Elevate.exe CMD.exe /Q /C For %%%%A In (\"\"%%1\"\") Do Netsh Advfirewall Firewall Add Rule Name=\"\"%%~nA\"\" Dir=Out Action=Block Program=\"\"%%1\"\""