Attention all Perl consultants here in the Monastery:
As a public service, I'd like to keep a list of monks who
take freelance consulting jobs. I'd keep this list on
my home node, so that whenever someone comes along saying they
need a "sample" script to do something, I can point him
to the list of Monks who will gladly take the job for hire.
Mind you, I'm not talking about people who are legitimately looking
for help with projects. I'm talking about people who want
to just get their job done for them.
Yes, I'm serious. /msg me and I'll put you on the list.
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
| [reply] |
At this node Monitoring Windows Registry Changes
by Eustaquio on Aug 03, 2001 at 23:18 someone with a login that happens to match your name posed the very same question. Perhaps you might like to have a look at the answers?
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
Sorry, Eustaquio, for not replying to the previous thread on this subject. I very often don't respond to requests for "sample scripts" because I very rarely have scripts lying about that can do what was asked without also having lots of other things in them that would just confuse the type of person who asks for a "sample script".
If you want to get help, you will have much better luck if you show your script to us. It is much less work for us to look over your script and help you figure out why it isn't working than it is for us to create a whole script that would actually work for you. For one thing, "the devil is in the details" and what seems like a clean, simple specification like you've given is likely to net you a sample script that doesn't work very well for your details.
Anyway, the Win32::TieRegistry barely mentions RegistryNotifyChangeKeyValue(). But the referenced Win32API::Registry documentation covers it in more detail:
- RegNotifyChangeKeyValue( $hKey, $bWatchSubtree, $uNotifyFilter, $hEvent, $bAsync )
-
Arranges for your process to be notified when part of the Registry
is changed.
$hKey is the handle to a Registry key [either HKEY_* or from
a previous call] for which you wish to be notified when any changes
are made to it.
If $bWatchSubtree is true, then changes to any subkey or
descendant of $hKey are also reported.
$iNotifyFilter controllers what types of changes are reported. It
is a numeric value containing one or more of the following bit masks:
- REG_NOTIFY_CHANGE_NAME
-
Notify if a subkey is added or deleted to a monitored key.
- REG_NOTIFY_CHANGE_LAST_SET
-
Notify if a value in a monitored key is added, deleted, or modified.
- REG_NOTIFY_CHANGE_SECURITY
-
Notify a security descriptor of a monitored key is changed.
- REG_NOTIFY_CHANGE_ATTRIBUTES
-
Notify if any attributes of a monitored key are changed [class
name or security descriptors].
$hEvent is ignored unless $bAsync is true. Otherwise, $hEvent
is a handle to a Win32 event that will be signaled when changes are
to be reported.
If $bAsync is true, then RegNotifyChangeKeyValue() returns
immediately and uses $hEvent to notify your process of changes.
If $bAsync is false, then RegNotifyChangeKeyValue() does
not return until there is a change to be notified of.
This routine does not work with Registry keys on remote computers.
When using this with Win32::TieRegistry, note that you omit the $hKey argument:
$key->RegNotifyChangeKeyValue(
$bWatchSubtree, $uNotifyFilter, $hEvent, $bAsync )
or die "Can't watch for changes: $^E\n";
also, you should import the REG_NOTIFY_* contants by specifying ":REG_" in your "use Win32::TieRegistry" statement.
So, with all of that, you should be able to get something that works. Come back and post if you have problems and we'll probably be able to offer more help. Especially if you show us what you've done so far (either exactly or, often better, an exact minimal example that exhibits the same problem), exactly how it fails (including exact error messages), exactly what you wanted it to do instead, and perhaps specifics about the version of operating system, Perl, and modules that you are using.
-
tye
(but my friends call me "Tye") | [reply] [d/l] [select] |
I am using this in a windowless compile to monitor my pppoe ip and upload a modified html template to my providers web site. Works well, no leaks. This is the core of the script:
use Win32::TieRegistry qw( :REG_ :KEY_ );
$regkey = "Some_Registry_Key_Under_HKLM";
waitForChange();
sub waitForChange {
$machKey= $Registry->Open( "LMachine", {Access=>KEY_READ(),Delimit
+er=>"/"} ) or die( "Can't open HKEY_LOCAL_MACHINE key: $^E\n" );
$key = $machKey->Open($regkey) or die( "Can't open key: $^E\n" );
$TiedHashRef = $key->TiedRef;
$TiedHashRef->RegNotifyChangeKeyValue( 1, REG_NOTIFY_CHANGE_LAST_S
+ET, 0, 0 ); # block until key changes.
# Key has changed... do something
waitForChange(); # restart the change notifier
}
exit();
| [reply] [d/l] |