[python-win32] PythonCOM & Windows Firewall
Metz, Bobby W, WWCS
bwmetz at att.com
Mon May 22 18:42:20 CEST 2006
Again, thanks to Roger to the perfect tip. As I feared,
non-admins don't get prompted to "allow" an app that's requesting access
or I'm doing something wrong. But, this did lead me to write a couple
of quick routines for detecting the FW condition for the users and
providing a nice little notification so they know to contact the Help
Desk for assistance.
Also thought I'd share these to save someone else the time down
the road. Note, the first function should theoretically detect Windows
XP of any flavor running SP2 or later. Only time will tell...it's based
on VB code to detect XP Prof with SP2. Modify as needed. I use them in
tandem since SP2 is the only XP with FW enabled by default. I won't
vouch for the FW detection in pre-SP2 or any other version using the ICF
as I don't have a test machine at the moment to try it.
# Using Python to detect if XP Firewall is enabled.
XPFW_Policy = XPFW.LocalPolicy.CurrentProfile
# Can't dispatch or access the FW COM instance.
# Using Python to detect if XP SP 2 is installed.
objWMIService = win32com.client.GetObject("winmgmts:")
objOS = objWMIService.ExecQuery ("Select * from
Win32_OperatingSystem WHERE Caption LIKE 'Microsoft Windows XP%' AND
ServicePackMajorVersion >= 2")
if objOS.Count != 0: # objOS.Count
on Win2000 is invalid (raises com_error)
# Can't access WMI so default to False.
# Maybe add some fancier error handling later.
# No COM errors but not Win XP
From: Metz, Bobby W, WWCS
Sent: Thursday, May 18, 2006 12:46 AM
To: 'Roger Upole'; python-win32 at python.org
Subject: RE: [python-win32] Re: PythonCOM & Windows Firewall
Roger, thanks for the code. I'll give it a try. Having read a bunch of
the documentation though, I'm concerned it may not work as some of our
users won't have admin rights. I was hoping this would provide them the
Zone Alarm type prompt so that non-admin could approve the listening app
upon execution. If all else fails it gives me a starter for checking
for existing exceptions.
Here's to hoping!!!
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of Roger Upole
Sent: Wednesday, May 17, 2006 7:07 PM
To: python-win32 at python.org
Subject: [python-win32] Re: PythonCOM & Windows Firewall
I've used it to list firewall exceptions, and it wasn't too much
more work to add an application:
for app in apps:
print app.Name, app.ProcessImageFileName
Python-win32 mailing list
Python-win32 at python.org
More information about the Python-win32