Reading subkeys, not values, with TieRegistry?
Reading subkeys, not values, with TieRegistry?
am 19.12.2006 19:42:48 von Deane.Rothenmaier
This is a multipart message in MIME format.
--===============0342431447==
Content-Type: multipart/alternative;
boundary="=_alternative 0066CF5686257249_="
This is a multipart message in MIME format.
--=_alternative 0066CF5686257249_=
Content-Type: text/plain; charset="us-ascii"
Gurus,
I'm hoping there's a way to read a selected level of registry subkeys.
Specifically, I'm looking for IE Trusted Sites stored as IP addresses.
They're stored as:
HKU//Software/Microsoft/Windows/CurrentVersion/Internet
Settings/ZoneMap/Ranges/RangeX//:Range
where X increments for each new Trusted Site IP added (Range1, Range2,
Range3, ... ), and the data for :Range is the IP address (the prepended
colon is part of the value's name), stored one per RangeX subkey. What I
need to do is find the highest, well, the next open, value for X.
Examples:
If the subkeys Range1, Range2, and Range3 all exist, "Range4" should be my
return, so I know that I can add a new IP as a :Range value under that
subkey.
If the subkeys Range1, Range3, and Range4 exist, I should get "Range2"
returned, since it's open for use.
What I need to do is, through Perl, add Trusted Sites to the registry as
IP addresses.
What I'm hoping to avoid is having to do a horrible for loop like this...
for $x (1..10_000) {
$foo = "HKU/.../Ranges/Range" . $x . "//:Range";
# Try reading value of $foo to see if it exists,
# exit loop on first failure (first nonexistent subkey).
}
I don't want to do that, mostly because I don't know the terminal
value--how high X might get--so I might have to use something as lame as
10_000. Ugh!
Thanks for your help,
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"In theory there is no difference between theory and practice. In practice
there is." -- Yogi Berra
--=_alternative 0066CF5686257249_=
Content-Type: text/html; charset="us-ascii"
Gurus,
I'm hoping there's a way to read a selected level of registry subkeys. Specifically, I'm looking for IE Trusted Sites stored as IP addresses. They're stored as:
HKU/<user SID>/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ZoneMap/Ranges/RangeX//:Range
where X increments for each new Trusted Site IP added (Range1, Range2, Range3, ... ), and the data for :Range is the IP address (the prepended colon is part of the value's name), stored one per RangeX subkey. What I need to do is find the highest, well, the next open, value for X.
Examples:
If the subkeys Range1, Range2, and Range3 all exist, "Range4" should be my return, so I know that I can add a new IP as a :Range value under that subkey.
If the subkeys Range1, Range3, and Range4 exist, I should get "Range2" returned, since it's open for use.
What I need to do is, through Perl, add Trusted Sites to the registry as IP addresses.
What I'm hoping to avoid is having to do a horrible for loop like this...
for $x (1..10_000) {
$foo = "HKU/.../Ranges/Range" . $x . "//:Range";
# Try reading value of $foo to see if it exists,
# exit loop on first failure (first nonexistent subkey).
}
I don't want to do that, mostly because I don't know the terminal value--how high X might get--so I might have to use something as lame as 10_000. Ugh!
Thanks for your help,
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra
--=_alternative 0066CF5686257249_=--
--===============0342431447==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0342431447==--
Re: Reading subkeys, not values, with TieRegistry?
am 19.12.2006 20:54:39 von dbecoll
Deane.Rothenmaier@walgreens.com wrote:
>
> Gurus,
>
> I'm hoping there's a way to read a selected level of registry subkeys.
> Specifically, I'm looking for IE Trusted Sites stored as IP addresses.
> They're stored as:
>
> HKU//Software/Microsoft/Windows/CurrentVersion/Internet
> Settings/ZoneMap/Ranges/RangeX//:Range
>
> where X increments for each new Trusted Site IP added (Range1, Range2,
> Range3, ... ), and the data for :Range is the IP address (the prepended
> colon is part of the value's name), stored one per RangeX subkey. What
> I need to do is find the highest, well, the next open, value for X.
>
> Examples:
>
> If the subkeys Range1, Range2, and Range3 all exist, "Range4" should be
> my return, so I know that I can add a new IP as a :Range value under
> that subkey.
>
> If the subkeys Range1, Range3, and Range4 exist, I should get "Range2"
> returned, since it's open for use.
>
> What I need to do is, through Perl, add Trusted Sites to the registry as
> IP addresses.
>
> What I'm hoping to avoid is having to do a horrible for loop like this...
>
> for $x (1..10_000) {
> $foo = "HKU/.../Ranges/Range" . $x . "//:Range";
> # Try reading value of $foo to see if it exists,
> # exit loop on first failure (first nonexistent subkey).
> }
>
> I don't want to do that, mostly because I don't know the terminal
> value--how high X might get--so I might have to use something as lame as
> 10_000. Ugh!
Unless you have a lot of other stuff under .../Ranges/ :
my $SID = "I assume you have this already";
my $key = "Users/$SID/Software/Microsoft/Windows/CurrentVersion/Intern et Settings/ZoneMap/Ranges";
print "key=$key\n";
my $Key = new Win32::TieRegistry $key, {
Access => 'KEY_ALL_ACCESS', Delimiter => '/' };
die "Bad key" if not $Key;
my @ranges = ();
foreach my $subKey ($Key->SubKeyNames) {
# You can do whatever you want to skip any subkeys that aren't appropos
push @ranges, $subKey if $subKey =~ /^Range\d+/;
}
print "Ranges:\n";
print "$_\n" foreach @ranges;
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Reading subkeys, not values, with TieRegistry?
am 19.12.2006 23:38:09 von Jeff Holt
This is a multi-part message in MIME format.
--===============1844449661==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C723BE.5C2212A6"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C723BE.5C2212A6
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
The following will print the list of gaps in the order you desire.
=20
use Win32::TieRegistry (Delimiter=3D>"/");
my $path =3D "CUser/Software/Microsoft/Windows/CurrentVersion/Internet =
Settings/ZoneMap/Ranges";
my @int;
for my $subkey ($Registry->{$path}->SubKeyNames) {
$int[$1] =3D 1 if $subkey =3D~ /Range(\d+)/;
}
my @gaps;
for (my $i=3D1; $i<$#int; $i++) {
push @gaps, $i unless defined $int[$i];
}
print join("\n", @gaps);
=20
However, if you want only the first available gap, then the following =
will take less time to compute.
=20
use Win32::TieRegistry (Delimiter=3D>"/");
my $path =3D "CUser/Software/Microsoft/Windows/CurrentVersion/Internet =
Settings/ZoneMap/Ranges";
my @int;
for my $subkey ($Registry->{$path}->SubKeyNames) {
$int[$1] =3D 1 if $subkey =3D~ /Range(\d+)/;
}
for (my $i=3D1; $i<$#int; $i++) {
unless (defined $int[$i]) {
print "$i\n";
exit 0;
}
}
________________________________
From: activeperl-bounces@listserv.ActiveState.com on behalf of =
Deane.Rothenmaier@walgreens.com
Sent: Tue 12/19/2006 12:42 PM
To: activeperl@listserv.ActiveState.com
Subject: Reading subkeys, not values, with TieRegistry?
Gurus,=20
I'm hoping there's a way to read a selected level of registry subkeys. =
Specifically, I'm looking for IE Trusted Sites stored as IP addresses. =
They're stored as:=20
HKU//Software/Microsoft/Windows/CurrentVersion/Internet =
Settings/ZoneMap/Ranges/RangeX//:Range=20
where X increments for each new Trusted Site IP added (Range1, Range2, =
Range3, ... ), and the data for :Range is the IP address (the prepended =
colon is part of the value's name), stored one per RangeX subkey. What =
I need to do is find the highest, well, the next open, value for X.=20
Examples:=20
If the subkeys Range1, Range2, and Range3 all exist, "Range4" should be =
my return, so I know that I can add a new IP as a :Range value under =
that subkey.=20
If the subkeys Range1, Range3, and Range4 exist, I should get "Range2" =
returned, since it's open for use.=20
What I need to do is, through Perl, add Trusted Sites to the registry as =
IP addresses.=20
What I'm hoping to avoid is having to do a horrible for loop like =
this...=20
for $x (1..10_000) {=20
$foo =3D "HKU/.../Ranges/Range" . $x . "//:Range";=20
# Try reading value of $foo to see if it exists,=20
# exit loop on first failure (first nonexistent subkey).=20
}=20
I don't want to do that, mostly because I don't know the terminal =
value--how high X might get--so I might have to use something as lame as =
10_000. Ugh!=20
Thanks for your help,=20
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"In theory there is no difference between theory and practice. In =
practice there is." -- Yogi Berra
------_=_NextPart_001_01C723BE.5C2212A6
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
=0A=
CONTENT=3D"text/html; charset=3Dunicode">=0A=
=0A=
=0A=
=0A=
The following =
will print the =0A=
list of gaps in the order you desire.
=0A=
=0A=
use =
Win32::TieRegistry =0A=
(Delimiter=3D>"/");
my $path =3D =0A=
"CUser/Software/Microsoft/Windows/CurrentVersion/Internet =0A=
Settings/ZoneMap/Ranges";
my @int;
for my $subkey =0A=
($Registry->{$path}->SubKeyNames) {
$int[$1] =3D 1 if =
$subkey =3D~ =0A=
/Range(\d+)/;
}
my @gaps;
for (my $i=3D1; $i<$#int; $i++) =0A=
{
push @gaps, $i unless defined $int[$i];
}
print =
join("\n", =0A=
@gaps);
=0A=
=0A=
However, if you want only the =
first =0A=
available gap, then the following will take less time to =
compute.
=0A=
=0A=
use =
Win32::TieRegistry =0A=
(Delimiter=3D>"/");
my $path =3D =0A=
"CUser/Software/Microsoft/Windows/CurrentVersion/Internet =0A=
Settings/ZoneMap/Ranges";
my @int;
for my $subkey =0A=
($Registry->{$path}->SubKeyNames) {
$int[$1] =3D 1 if =
$subkey =3D~ =0A=
/Range(\d+)/;
}
for (my $i=3D1; $i<$#int; $i++) =
{
unless =0A=
(defined $int[$i]) {
=0A=
print =
"$i\n";
=0A=
exit =
0;
=0A=
size=3D1> }
face=3D"Courier New" size=3D1>}
=0A=
=0A=
=0A=
=0A=
From: =0A=
activeperl-bounces@listserv.ActiveState.com on behalf of =0A=
Deane.Rothenmaier@walgreens.com
Sent: Tue 12/19/2006 12:42 =0A=
PM
To: activeperl@listserv.ActiveState.com
Subject: =
Reading =0A=
subkeys, not values, with TieRegistry?
=0A=
Gurus,
face=3Dsans-serif size=3D2>I'm hoping there's a way to read a selected =
level of =0A=
registry subkeys. Specifically, I'm looking for IE Trusted Sites stored =
as IP =0A=
addresses. They're stored as:
size=3D2>HKU/<user =
SID>/Software/Microsoft/Windows/CurrentVersion/Internet =0A=
Settings/ZoneMap/Ranges/RangeX//:Range
face=3Dsans-serif =0A=
size=3D2>where X increments for each new Trusted Site IP added (Range1, =
Range2, =0A=
Range3, ... ), and the data for :Range is the IP address (the prepended =
colon is =0A=
part of the value's name), stored one per RangeX subkey. What I =
need to do =0A=
is find the highest, well, the next open, value for X. =
face=3Dsans-serif size=3D2>Examples:
face=3Dsans-serif size=3D2>If =0A=
the subkeys Range1, Range2, and Range3 all exist, "Range4" should be my =
return, =0A=
so I know that I can add a new IP as a :Range value under that =
subkey. =0A=
If the subkeys Range1, Range3, =
and Range4 =0A=
exist, I should get "Range2" returned, since it's open for use. =0A=
What I need to do is, through =
Perl, add =0A=
Trusted Sites to the registry as IP addresses.
face=3Dsans-serif size=3D2>What I'm hoping to avoid is having to do a =
horrible for =0A=
loop like this...
for =
$x =0A=
(1..10_000) {
=
$foo =3D =0A=
"HKU/.../Ranges/Range" . $x . "//:Range";
face=3D"Courier New" =0A=
size=3D2> # Try reading value of $foo to see if it =
exists, =0A=
# exit loop on =
first failure =0A=
(first nonexistent subkey).
size=3D2>} =0A=
I don't want to do that, mostly =
because I =0A=
don't know the terminal value--how high X might get--so I might have to =
use =0A=
something as lame as 10_000. Ugh!
size=3D2>Thanks for your help,
size=3D2>
Deane =0A=
Rothenmaier
Systems Architect
Walgreens =
Corp.
847-914-5150
"In =0A=
theory there is no difference between theory and practice. In practice =
there =0A=
is." -- Yogi Berra
=0A=
------_=_NextPart_001_01C723BE.5C2212A6--
--===============1844449661==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1844449661==--