Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

To all humans on this site

can you please show me how can I delete a registry sub key(with sub keys values in it)....Thanks.

Here is my code
use strict; use Win32::Service; use Win32::Registry; use vars qw/%data @source @target/; if ($HKEY_LOCAL_MACHINE->Connect($ARGV[0], my $root)) { print "\nSuccessfully connect to remote registry on $ARGV[0]\n"; if ($root->Open("SYSTEM\\CurrentControlSet\\Control\\Print\\printer +s", my $Key)) { print "Obtaining printer information....Please wait\n"; my @keys; my $counter = 0; $Key->GetKeys( \@keys ); print "\nPrinters found on machine : $ARGV[0]\n"; for my $subkey ( @keys ) { print "$subkey\n"; &deleteReg($Key,"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSe +t\\Control\\Print\\printers\\".$subkey); } $Key->Close; } $root->Close; } else { print "\nError: $^E \n"; } sub deleteReg { my( $key, $name )= @_; for( eval { keys %{$key->{$name}} } ) { deleteReg( $key, "$name\\$_" ); } delete $key->{$name}; }

Replies are listed 'Best First'.
Re: Win32 Registry
by tachyon (Chancellor) on Oct 18, 2004 at 01:48 UTC

    I would suggest you RTFM which you will find at Win32::Registry.

    $reg_obj->DeleteKey($key_name);

    Win32::Registry is now deprecated. You may find Win32::TieRegistry easier to use. With this module you can delete registry keys by dleteing from the tied hash.

    cheers

    tachyon