Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Screensaver defeat for Win32

by aplonis (Pilgrim)
on Jan 18, 2004 at 19:16 UTC ( #322202=CUFP: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: Screensaver defeat for Win32
by jplindstrom (Monsignor) on Jan 18, 2004 at 21:28 UTC
    I use these two .reg files to disable screen saver activation when that %& logon script has enabled it.

    Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\D +esktop] "SCRNSAVE.EXE"="logon.scr" "ScreenSaverIsSecure"="1" "ScreenSaveActive"="1" "ScreenSaveTimeOut"="0"
    Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Control Panel\Desktop] "ScreenSaveTimeOut"="0"



Re: Screensaver defeat for Win32
by graff (Chancellor) on Jan 19, 2004 at 01:49 UTC
    ...even in an emergency to turn off the hydraulic power to a given test rig we must putz around with a password!

    So, even with your keystroke emitter to keep the consoles from getting logged off so a password is never required... people still need to putz around with a keyboard and/or mouse to stop the rig?

    Isn't there supposed to be a big red "STOP" button next to the rig to handle that sort of emergency?

      Graff - Your right, big red button a.k.a. EMO better be there. You can not rely on SW as an interlock at least if you want to sell your product to anyone.
      Oh,yes. We do have a big red button. In fact there are several of them around the room. Alas, it shuts down the hydraulic pump, killing power to not just one test, but to ALL of them...the entire lab: eight load frames and nine bedplates. Only in a worst-case-scenario would I want to push that button. To save a coworker, yes! More often I have pressing need to shut down a single test rig to save a test sample, a one-of-a-kind prototype (or the instruments attached to it) from being destroyed.
Re: Screensaver defeat for Win32
by pboin (Deacon) on Jan 19, 2004 at 13:29 UTC
    While I understand the technical side of this story, and I understand the inconvenience of working with over-zealous timeouts, I'd kick your ass to the door if I found you side-stepping corporate security on a box that's important as you say it is.

    Sometimes, you change the code with an editor, sometimes you change the process with a phone call. You're not even sure if anyone ever did so much as ask! I don't mean to bust your balls, but I'm definitely one that encourages responsibility to fall on the shoulders that it *should*. IMO, it's a neat hack, but you're out of line, even if the PHB's *are* French...

Re: Screensaver defeat for Win32
by hessef (Monk) on Jan 19, 2004 at 16:14 UTC
    I agree with the previous poster, that the shutoff system should be a Big Red Button and not a keyboard.

    (semi-off topic)

    I had a somewhat similar problem in a C++ app. My program recorded audio and many people were recording long documents, not touching the keyboard/mouse while speaking and having the screen saver kick in. I fixed the problem by turning the screen saver off during recordings with the following Microsoft's Visual C++ code:

    (turn off the screen saver)
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0)

    (turn on the screen saver)
    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, 0, 0)

    While that isn't perl code, it might be possible for Perl to make a similiar system call. I don't know, but I'm placing the information here anyways in case it might help somebody wants to start looking for another way to turn off the screen saver.
Re: Screensaver defeat for Win32
by flyingmoose (Priest) on Feb 09, 2004 at 02:52 UTC
    Where I work we use Win2K boxes to control big, dangerous, servo-hydraulic test systems...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!

    Please let me know where you work so I will never sign up to work there.

Re: Screensaver defeat for Win32
by pjbondi (Initiate) on Mar 17, 2011 at 15:44 UTC

    Several years after your original post, this still works like a charm! Thank you. I suppose this is the #1 hit on google for screensaver defeat for a reason.

    I'm using ActiveState Perl build 1006

    Since the tk module is not installed by default, simply:

    ppm install tk


    Downloading Tk-804.028...done Unpacking Tk-804.028...done Generating HTML for Tk-804.028...done Updating files in site area...done 845 files installed

    I've found that changing from <space><backspace> to {SCROLLLOCK}{SCROLLLOCK} has less impact on any application which might be in the foreground. <space><backspace> would cause a Firefox application to navigate.

      Maybe you'd prefer the simpler Keep the playback rolling (Win32) which doesn't send any key strokes and just jiggles the mouse (and doesn't even have to do that) and automatically disables itself if you move the mouse. The thread includes several versions that have modified features, such as making it harder to accidentally disable.

      - tye        

        I had to update this thing due to a change at work (my 3rd employer since authoring the script). On their rolling out of the new Win7 boxen my script quit working. And get this! My company's IT department itself asked me if I might fix it. How cool is that?

        So I borrowed a loaner Win7 laptop, installed Strawberry Perl and changed the timing to update every minute (verus the fomer two minutes) and changed the default character set to a pair of SCROLLLOCK's (as per suggestion above). Those two in combination seem to have worked at least on this loaner laptop.

        While I was editing, I couldn't resist adding in a few new options. Foremost is to offer the choice of using Tye's mouse jiggle feature. This you may choose to employ either together-with or separately-from issuing key strokes. You also have a choice of key strokes.

        Lastly, while running it will check to see if the mouse has been already moved by the user. If it has then the script goes back to sleep for a further minute.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://322202]
Approved by Corion
Front-paged by rnahi
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-12-16 10:18 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (70 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!