Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, I may have solved my own problem.

After reading through the documentation some more, I found the Open method:

$subKey= $key->Open( $sSubKey, $rhOptions ) The Open method opens a Registry key and returns a new Win32::TieR +egistry object associated with that Registry key. If Open is called via a refe +rence to a tied hash, then Open returns another reference to a tied hash. Other +wise Open returns a simple object and you should then use TiedRef to get a refer +ence to a tied hash. $sSubKey is a string specifying a subkey to be opened. Alternately + $sSubKey can be a reference to an array value containing the list of increasing +ly deep subkeys specifying the path to the subkey to be opened. ...

Which seems to do the trick in my modified program:

#!/usr/bin/perl -w # # Attempt to delete 'HKEY_CLASSES_ROOT/Folder/shell/xyzzy_1' from the # Windows Registry, using Win32::TieRegistry. # # This version uses the 'Open' method -- Success! ## ############# # Libraries # ############# use strict; use warnings; use Data::Dumper; use Win32::TieRegistry( Delimiter => '/' ); ################ # Main Program # ################ # Step 1 -- assign to the 'Folder' key my $label = "xyzzy_1"; my $key = 'HKEY_CLASSES_ROOT/Folder'; my $h_folder = $Registry->{$key}; (defined $h_folder) or die "Unable to find registry key '$key'\n"; # Step 2 -- open at the 'shell' subkey my $h_shell = $h_folder->Open('shell', { 'Delimiter' => '/' }); $h_shell or die "Unable to open subkey 'shell' (of key '$key')\n"; # Step 3 -- Display values for the 'shell' subkey print "[Values for '$key/shell']\n"; my $idx = 0; foreach my $key (keys %$h_shell) { printf " %3d. %s\n", ++$idx, $key; } print "\n\n"; # Step 4 -- Validate that the label 'xyzzy_1' was found if (!exists($h_shell->{"$label/"})) { die "No such label for '$key' => '$label'\n"; } # Step 5 -- Delete 'xyzzy_1' from the 'shell' subkey print "Deleting label '$label' ...\n"; my $result = delete($h_shell->{"$label/"}); printf "Result of delete: '%s'\n", Dumper($result);

One caveat is that, if the regedit program is open, you must refresh its state after the delete (View > Refresh or function key F5), otherwise the display will continue to show the deleted key (eg. 'xyzzy_1'), but clicking on it (and other operations) will give a regedit error.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Unable to delete registry keys using Win32::TieRegistry by liverpole
in thread Unable to delete registry keys using Win32::TieRegistry by liverpole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-04-18 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found