Where I work we use Win2K boxes to control big, dangerous, servo-hydraulic test systems. The HQ in France mandates a 3-minute lockout on all PC's. This means that even in an emergency to turn off the hydraulic power to a given test rig we must putz around with a password!

Our IT department blames HQ in France for refusing to listen to reason. My own suspicion is that our IT is so timid they won't even ask. In desperation (for the sake of my co-workers' wish to retain their body parts) I wrote this script in Perl. It now runs on all ten MTS test rigs.

All it does is constantly re-trip the screensaver with a space/backspace thereby defeating the 3-minute timeout for login. At 2300 hours it will exit. You can even pause it for lunch or whatever.

#!c:\perl\bin\perl.exe -w use Tk; use Win32::OLE; ###################### # Begin user defaults # (Stuff you can change) ###################### $loop_minutes = 2; # How many minutes between trips $char_string = "\040\010"; # What char string to trip the shell with. $exit_time_regex = "23:[0-9]{2}:[0-9]{2}"; # When to exit program. ###################### # End user defaults # Begin GUS subs ###################### # Return Date Time Group in ISO 8601 approved fashion. sub update_DTG { my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) + = localtime(time); my $DTG = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $year + 1900, $mon + + 1, $mday, $hour, $min, $sec ); return ("$DTG"); } # Send a character string to trip any screensaver. sub trip_screensaver { $WshShell = new Win32::OLE 'WScript.Shell' || die "No new shell object $! $?"; $WshShell->SendKeys($char_string); } ###################### # End GUS subs # Begin GUI stuff ###################### # First declare the main GUI frame and all her daughters. my $mw = MainWindow->new( -title => ' Screensaver Delay' ); my $fm_top = $mw->Frame( -relief => 'flat', -borderwidth => 5 ); # Make all the frames. my $fm_btm = $mw->Frame( -relief => 'flat', -borderwidth => 5 ); # Build the label and entry box widgets for the 'File path' frame. $fm_top->Entry( -textvariable => \$last_trip, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x' ); $fm_btm->Button( -text => ' Start ', -command => \&start_tripping, -background => 'gray', -activebackground => 'red', -relief => 'raised', )->pack( -side => 'left', -expand => 1, -fill => 'x' ); $fm_btm->Button( -text => ' Pause ', -command => \&stop_tripping, -background => 'gray', -activebackground => 'blue', -relief => 'raised', )->pack( -side => 'left', -expand => 1, -fill => 'x' ); $fm_btm->Button( -text => ' Exit ', -command => \&exit, -background => 'gray', -activebackground => 'green', -relief => 'raised', )->pack( -side => 'left', -expand => 1, -fill => 'x' ); # Pack all the frames last. $fm_top->pack( -side => 'top', -expand => 1, -fill => 'x' ); $fm_btm->pack( -side => 'top', -expand => 1, -fill => 'x' ); $trip_flag = 0; sub start_tripping { $last_trip = "SS Delay Engaged."; $trip_flag = 1; } sub stop_tripping { $last_trip = "SS Delay Paused."; $trip_flag = 0; } $mw->repeat( $loop_minutes * 60 * 1000, \&ss_trip ); sub ss_trip { exit if update_DTG =~ /$exit_time_regex/; if ( $trip_flag ) { trip_screensaver(); $last_trip = update_DTG(); } } MainLoop;

janitored by ybiC: Balanced <readmore> tags around long codeblock, to avoid uneccessary vertical scrolling


In reply to Screensaver defeat for Win32 by aplonis

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.