windows registry, tuples, turning off winXP firewall with Python

B

Bart Nessux

for i in range(10000):
try:
n,v,t = EnumValue(open_key,i)
# n == name of the registry object.
# v == object's value.
# t == object's type.
print n,v,t
except EnvironmentError:
print "\nThere are", i, "registy objects under this key."
break

Is there a way to reference an item within a tuple that you've iterated
over? The above code upacks a tuple into 3 variables n,v and t. In order
to do this, it loops over a Windows registry key. Let's say that I want
to find out which n == 'EnableFirewall' and then read the value of its
v... how can I do that?

BTY, the below code turns off the 'Windows Firewall' on Windows XP
Service Pack 2... I wrote it as a test after reading that MS is allowing
3rd party programs to programmatically enable or disable the firewall
through the registry.

from _winreg import *

sub_key =
r"SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile"
open_key = OpenKey(HKEY_LOCAL_MACHINE, sub_key, 0, KEY_ALL_ACCESS)
SetValueEx(open_key,'EnableFirewall',0,REG_DWORD,0)
CloseKey(open_key)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top