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

Hi Monks

I can't seem to be able to delete a Win32 registry key!

Is there something special in "Perl" that I need to do before I can delete the damn thing?
#! c:/perl/bin/perl.exe -slw 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 ) { next unless ($subkey =~/,,Winxpps01/); print "Deleting : $subkey\n"; $Key->DeleteKey($subkey); # Please F Off and go away. } $Key->Close; } $root->Close; } else { print "\nError: $^E \n"; }
Thanks in advance for your help

UPDATE

I even Tried this
use strict; 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 ); for my $subkey ( @keys ) { next unless ($subkey =~/,,Winxpps01/); print "$subkey\n"; $Key->Open( $subkey, my $x ) or die $^E; my %vals; $x->GetValues( \%vals ); for my $item (values %vals) { print "$item\n"; $x->DeleteValue( $item); } $Key->DeleteKey($subkey); } $Key->Close; } } else { print "\nError: $^E \n"; }
Still to no avail....can some pleae help?
Blackadder

Replies are listed 'Best First'.
Re: How can I delete Win32 registry keys?
by pg (Canon) on Oct 17, 2004 at 20:42 UTC

    First of all, use Win32::TieRegistry, Win32::Registry is obsolete.

    Take a look at its DeleteKey and DeleteValue function.

    use Win32::Registry; use Data::Dumper; use strict; use warnings; my $perl; $::HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Perl", $perl); $perl->DeleteValue('BinDir');
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How can I delete Win32 registry keys? (pointer)
by tye (Sage) on Oct 18, 2004 at 05:31 UTC
      Hi - very sorry and many thanks.

      here what I have now;
      use strict; use Win32::Registry; use vars qw/%data @source @target @missing/; 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", my $Ke +y)) { print "Obtaining printer information....Please wait\n"; my @keys; $Key->GetKeys( \@keys ); print "\nListing printers found on source machine\n"; print "\n------------------------------------------------------- +------\n"; for my $subkey ( @keys ) { print "\n\nSubKey : $subkey\n"; $Key->Open( $subkey, my $x ) or die $^E; my %vals; my @vals; $x->GetKeys( \@vals ); for my $item (@vals) { next if ($item !~ /^,,My_print_server01/); print "Items within : $item\n"; regDelTree($item, "HKEY_LOCAL_MACHINE\\System\\CurrentCont +rolSet\\Control\\Print\\Printers\\") } } $Key->Close; } } else { die"FATAL ERROR : NO SOURCE MACHINE $ARGV[0], $^E\n"; } sub regDelTree { my $rootKey= shift @_; # Reg key to del subtree from my $keyName= shift @_; # Name of key to delete { my $key= $rootKey->{$keyName}; if( ! $key ) { warn "Can't open $keyName in ", $rootKey->Path(), ": $^E\n"; return; } for( $key->SubKeyNames() ) { regDelTree( $key, "$_\\" ); } } delete $rootKey->{$keyName} or warn "Can't delete $keyName from ", $rootKey->Path(), ": $^E\n"; }
      And I get this error
      C:\Perl>comp_apps1.pl Remote_WorkStation01 Successfully connect to remote registry on Remote_WorkStation01 Obtaining printer information....Please wait Listing printers found on source machine ------------------------------------------------------------- SubKey : Environments SubKey : Forms SubKey : Monitors SubKey : PendingUpgrades SubKey : Providers SubKey : Printers Items within : ,,My_print_server01,Printer_device200 Can't use string (",,My_print_server01,Printer_device200") as a HASH r +ef while "strict refs" in use at C:\Perl\comp_apps1.pl line 40. C:\Perl>
      Any Advise Please?,....Many thanks in advance.

      Regards
      Blackadder
Re: How can I delete Win32 registry keys?
by talexb (Chancellor) on Oct 18, 2004 at 02:55 UTC
      I can't seem to be able to delete a Win32 registry key!
      Is there something special in "Perl" that I need to do before I can delete the damn thing?

    OK, we have your code. What does it do? How does it fail? How do you that it is failing? What does the documentation say?

    We can only help you if you give us an idea of what your problem is.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds