Page 1 of 1

[SOLVED] Example of creating a Windows firewall rule

Published: October 2, 2024 - 11:06 AM
by gaelds
Hello,

could you please provide a code example for adding a firewall rule in Windows? The mBlock package is blocked when installed on machines where the firewall is enabled. I noticed this when manually running the mBlock 5.4.3 installation executable.

Re: Example of creating a Windows firewall rule

Published: October 2, 2024 - 3:09 PM
by jlepiquet
Good morning,

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

def install():

    print(run('netsh advfirewall firewall add rule name="orbixd" program="%s" action=block dir=in profile=domain enable=no' % r'C:\program files\dassault systemes\b24\win_b64\code\bin\orbixd.exe'))
    print(run('netsh advfirewall firewall add rule name="DMUV5" program="%s" action=block dir=out profile=domain enable=yes'% r'C:\program files\dassault systemes\b24\win_b64\code\bin\DMU.exe'))

Re: Example of creating a Windows firewall rule

Published: October 2, 2024 - 3:40 PM
by gaelds
Thanks! I imagined there were setuphelper functions that I hadn't found. I'll try with netsh.

Regards

Re: Example of creating a Windows firewall rule

Published: October 2, 2024 - 5:01 PM
by jlepiquet
Good morning,

There is the command setuphelpers.add_netfirewallrule()
https://www.wapt.fr/apidoc/wapt-2.5/win ... rewallrule

Code: Select all

add_netfirewallrule(rule_name="orbixd", app_path='C:\program files\dassault systemes\b22\win_b64\code\bin\orbixd.exe', action="block", direction="Inbound", profile="domain", enabled=False)

Re: Example of creating a Windows firewall rule

Published: October 3, 2024 - 8:02 AM
by gaelds
Ah cool, thanks! That's exactly what I was looking for, but I must have searched very badly...

Re: Example of creating a Windows firewall rule

Published: October 3, 2024 - 9:28 AM
by dcardon
Hi Gaël,

thanks for the feedback. There's a lot of information in the setuphelpers, and perhaps we don't highlight it enough. :-)

I'm marking the topic as RESOLVED.

Regards,

Denis