skon2464 Posted July 22, 2013 Posted July 22, 2013 (edited) I am trying to add a firewall rule but I think I got the syntax wrong. Run(@ComSpec & "/k " & 'netsh advfirewall firewall add rule name=' & '"New"' & 'dir=in action=allow program=' & NoSlash(@ScriptDir) & '"\MyApp.exe"' & 'enable=yes') Could you please let me know what I missed. Edited July 22, 2013 by skon2464
FireFox Posted July 22, 2013 Posted July 22, 2013 Hi, Welcome to the autoit forum I don't know about the syntax, but I advice you to take a look at this topic : '?do=embed' frameborder='0' data-embedContent>> Br, FireFox.
DW1 Posted July 22, 2013 Posted July 22, 2013 The syntax issue is likely to do with your lack of spaces between parameters. Also, you messed up on quoting the app name, not including the path. -Added space before "dir=" -Added space before "enable=" -Moved double quote from before "MyApp.exe" to right after "program=" Run(@ComSpec & "/k " & 'netsh advfirewall firewall add rule name=' & '"New"' & ' dir=in action=allow program="' & NoSlash(@ScriptDir) & '\MyApp.exe"' & ' enable=yes') AutoIt3 Online Help
skon2464 Posted July 23, 2013 Author Posted July 23, 2013 I am able to figure out the problem. Thanks guys
naru Posted August 25, 2017 Posted August 25, 2017 On 7/22/2013 at 10:59 PM, DW1 said: The syntax issue is likely to do with your lack of spaces between parameters. Also, you messed up on quoting the app name, not including the path. -Added space before "dir=" -Added space before "enable=" -Moved double quote from before "MyApp.exe" to right after "program=" Run(@ComSpec & "/k " & 'netsh advfirewall firewall add rule name=' & '"New"' & ' dir=in action=allow program="' & NoSlash(@ScriptDir) & '\MyApp.exe"' & ' enable=yes') Not working
LWC Posted March 29, 2024 Posted March 29, 2024 (edited) On 8/25/2017 at 4:36 PM, naru said: Not working Probably because it needs admin privileges. I therefore run it not with Run but with ShellExecute with runas verb (although I prefer ShellExecuteWait as shown below to know if the rule worked or not). BTW, you can alternatively use direct firewall API but it means having to run the entire script as admin which is a security risk. $failed=False If ShellExecuteWait('netsh', 'advfirewall firewall add rule name="' & $programName & '"' & ' dir=in action=block program="' & $programPath & $programFile & '"', default, "runas") > 0 $failed=True ElseIf ShellExecuteWait('netsh', 'advfirewall firewall add rule name="' & $programName & '"' & ' dir=out action=block program="' & $programPath & $programFile & '"', default, "runas") > 0 $failed=True EndIf And to delete a rule: $failed=False If ShellExecuteWait('netsh', 'advfirewall firewall delete rule name="' & $programName & '"' & ' program="' & $programPath & $programFile & '"', default, "runas") > 0 then $failed = True EndIf Edited March 29, 2024 by LWC Rephrased
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now