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

O' Holy Monks ***** PLEASE PLEASE HELP *****

I have installed many printers on many remote WinXP PCs incorrectly via a Perl script working as shell around the PSEXEC utility. I need to remove them all now. All those printers were installed from \\print_server\printer_name remote share. In addition, all appear in the printers and faxes folder on the WinXP PC (and they all show as inaccessible). None of these printers been shared locally (so I cannot use NetResource).

I tested this script to remove a printer; however, the registry entries do get removed but the printer icons still remains visible in the Printers and Faxes folder.
use Win32::TieRegistry; $printerKey= $Registry->{"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\P +rint\\Printers\\"} or die "Can't read Printers key: $^E\n"; @printers= keys( %{$printerKey} ); foreach $printer (@printers) { print $printerKey->{$printer."\\Name"}."\n"; if ($printerKey->{$printer."\\Name"}=~ /\\\\printer_server\\/) { delete $printerKey->{$printer."\\Name"}; } }
the script I used to add the printer (for all its damn worth) was this;
#!c:/perl/bin/perl.exe -w use strict; use vars qw/%data/; $data{printer_server}= "\\\\print_server\\"; $data{PSEXEC}="\\\\Remote_host\\C\$\\Tools\\PSTools\\PSEXEC\\psexec.ex +e"; $data{usr}= "XXX\\Blackadder_ad"; $data{pw}= "Supernatural2005"; $data{command}= " cmd.exe /c start"; open (LST, "$ARGV[0]") || die "File Name => $ARGV[0] $!\n"; chomp (@{$data{host_names}} = <LST>); for (@{$data{host_names}}) { print "$_ : "; &install_printers($_); } sub install_printers { my ($target) = @_; my $const = 'snp'; my $switches = ' -i -d -u '; print "$target : "; if ($target =~ /^SN01/) { print " First Flr Printers, "; for (1..9) { $_ = '10'.$_; `$data{PSEXEC} \\\\$target -i -d -u $data{usr} -p $data{pw} c +md /c start $data{printer_server}$const$_`; print "$const$_,"; } } if ($target =~ /^SN02/) { print " Second Flr Printers, "; for (0..7) { $_ = '20'.$_; `$data{PSEXEC} \\\\$target -i -d -u $data{usr} -p $data{pw} c +md /c start $data{printer_server}$const$_`; print "$const$_, "; } } print "\n"; } print "\n____________End of List____________\n";
Your help is highly appreciated (a code example triple so)

I have just downloaded Win32::Printer module (which I never used before) and see if there is anything in there that can help me.

Thanks
Blackadder

Replies are listed 'Best First'.
Re: Removing printers from remote WinXP PC
by jdtoronto (Prior) on Oct 13, 2004 at 17:49 UTC
    I have never done this form Perl. But I _HAVE_ done it from the commmand line (and surely if you can do it from the command line you can do it from Perl!). Look HERE for info, where you will also find a link to some Microsoft documents on the subject.

    Good luck!

    jdtoronto

      Thanks

      Found lots of useful stuff, but non that would sort my problem out.

      I can remove the driver for the printer, but I just need to find a way to remove those printer icons from the printers and faxes folders, so staff can see that those printers are removed.
      Blackadder
        I need to know how I can delete network printer from a remote pc via a script.

        Anyone else can help us out on this please

        Blackadder