[python-win32] windows firewall woes?

Andrew Hammond andrew.george.hammond at gmail.com
Fri Mar 9 01:16:48 CET 2012


With the following code,

def add_firewall_exception():
        app =
win32com.client.gencache.EnsureDispatch('HNetCfg.FwAuthorizedApplication',
0)
app.ProcessImageFileName = r'\Python26\python.exe'
app.Scope = NET_FW_SCOPE_ALL
app.IpVersion = NET_FW_IP_VERSION_ANY
app.Enabled = True

        firewall_manager =
win32com.client.gencache.EnsureDispatch('HNetCfg.FwMgr',0)
profile = firewall_manager.LocalPolicy.CurrentProfile
profile.AuthorizedApplications.Add(app)

I get the following error message:

E:\Documents and Settings\stubby\Desktop>python -OO -i firewall.py
>>> add_firewall_exception()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "firewall.py", line 41, in add_firewall_exception
    profile.AuthorizedApplications.Add(app)
  File
"E:\python26\lib\site-packages\win32com\gen_py\58FBCF7C-E7A9-467C-80B3-FC65E8FCCA08x0x1x0.py",
line 75, in Add
    return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), ((9, 1),),app
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None,
None, 0, -2147467261), None)
>>> ^Z

I'm not at all versed in win32com programming... any help please?

On Tue, Mar 6, 2012 at 8:05 AM, Bill Tutt <bill at tutts.org> wrote:

> This sounds more like a problem with your approach to servicing your
> product, and not necessarily a python windows specific problem.
>
> I can point you in the direction to create the firewall exception, but you
> would still need to figure out how to arrange to have the code actually
> execute.
>
> Windows Firewall rule exceptions don't appear that hard to define.
>
> Windows Firewall COM interfaces docs:
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa366449(v=vs.85).aspx
>
> Some simplistic VBScript examples of using those interfaces:
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa366421(v=vs.85).aspx
>
> I'd use the VBScript examples as a base and determine what kind of
> exception is best for your needs. (i.e. as little of an exception as
> possible)
>
> Bill
>
> On Mon, Mar 5, 2012 at 9:05 PM, Andrew Hammond <
> andrew.george.hammond at gmail.com> wrote:
>
>> We have python running on a number of devices in the field and have
>> experienced problems where it appears that a windows update has removed a
>> windows firewall exception, blocking our python service from operating.
>>
>> Has anyone else experienced something like this? Is there a way to fix it
>> without human intervention?
>>
>> Andrew
>>
>> _______________________________________________
>> python-win32 mailing list
>> python-win32 at python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120308/0ab761ce/attachment.html>


More information about the python-win32 mailing list