Hi Guys, I need to remove few printers that I have installed on lots of WinXP PCs. I tried few things, which all failed, and then I found a resource kit utility “cleanspl.exe” which works fine. Now I need to automate this utility by feeding it a list of host names to remove the printers from.

I started first by running the utility. Then I ran this code.

$|++; use strict; use Win32; use Win32::GuiTest qw(:ALL :SW); use vars qw /%data/; #$data{apps_list} = shift @ARGV; $data{host} = Win32::NodeName(); system (cls); my @windows = FindWindowLike(0, 'Clean Spooler'); for my $win (@windows) { print "Found window $win with title '", GetWindowText($win), "'\ +n"; my @children = GetChildWindows($win); for my $child (@children) { my $text = GetWindowText($child); next if ($text =~ /^\xff/); # you've found the icon next if ($text =~ /^OK|Cancel|Abort|Retry|Ignore|Yes|No$/); # + you've found a button print "Found child $child with text '$text'\n"; } }

And the out put I get is this

Found window 5440342 with title 'Clean Spooler' Found child 1245952 with text 'To restore the spooler to its original +state, enter the name of the computer on which to restore th e spooler, and click the Clean Spooler button. All print jobs, printe +rs, printer drivers, and spool files on the specified comput er will be deleted.' Found child 787128 with text 'Computer &Name:' Found child 5309426 with text '' Found child 787116 with text 'S&elect...' Found child 787136 with text '&Save Spooler Registry to File' Found child 1245870 with text '&File:' Found child 1835774 with text '' Found child 852698 with text '&Browse...' Found child 983782 with text '&Clean Spooler' Found child 656042 with text 'C&lose' Found child 918252 with text '' Found window 1245952 with title 'To restore the spooler to its origina +l state, enter the name of the computer on which to restore the spooler, and click the Clean Spooler button. All print jobs, prin +ters, printer drivers, and spool files on the specified comp uter will be deleted.' Found window 983782 with title '&Clean Spooler'

I need to insert the values (“\\\\”.host names) from a list into the filed ‘Computer &Name’ and click ‘Clean Spooler’ button. This followed by a sequence of yes, no ,no, no, no, no , yes. Then restarting the loop again with another host name…..easy!

Can someone please help me here and show me how I can insert a value in the ‘Computer &Name’ field to start of with?

Thanks

This is what I have done, but I don't think its good programming

use strict; use Win32::GuiTest qw( FindWindowLike SetForegroundWindow SendKeys PushChildButton GetChildWindows GetWindowText ); my @whnds = FindWindowLike( undef, "^Clean Spooler" ); if( !@whnds ) { die "Cannot find window with title/caption specified\n"; } else { printf( "Window handle of specified application is %x\n", $whnds[ 0 + ] ); SetForegroundWindow( $whnds[ 0 ] ); SendKeys( "\\\\SN02GET18a" ); SendKeys("{ENTER}"); SendKeys("{RIGHT}"); SendKeys("{ENTER}"); SendKeys("{RIGHT}"); SendKeys("{ENTER}"); SendKeys("{ENTER}"); }

Blackadder

janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention


In reply to Usin Win32::GuiTest to remove printers. by blackadder

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.