Jim Lawless' Blog


Invoking the Default Windows Screen-Saver

Originally published on: Wed, 09 Dec 2009 19:13:10 +0000

Please note! If you're having difficulties compiling the C source code presented below, please see my post: Compiling C from the Command Line with Pelles C

Several weeks ago, I posted code for a utility that prevents a Windows screen-saver from firing by simulating mouse motion ( http://www.mailsend-online.com/blog?p=47 ).

Today, I'm providing a short WSH JavaScript script that will invoke the default screen-saver. I noted a search for similar functionality that led to my blog. This post will be included in the "By Popular Demand" category of items requested via a search-engine.

runsaver.js


// Launch the default screen-saver
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

   var shl=new ActiveXObject("WScript.Shell");
   var ss=
      shl.RegRead(
         "HKEY_USERS\\.DEFAULT\\Control Panel\\Desktop\\SCRNSAVE.EXE");
      // Let's wait one second to make sure all fingers are off the keyboard and no further
      // mouse motion is happening...
   WScript.Sleep(1000);
      // Run the screen-saver
   shl.Exec(ss + " /s");

To invoke this script, you may enter one of the two following command-lines:


cscript runsaver.js

wscript runsaver.js

CScript will run the console version of the WSH interpreter engine; WScript will run the GUI version and will not display a console window.

You may create a shortcut to this script by using wscript.exe as the program to run and runsaver.js as the sole parameter. You might need to specify a full path for the runsaver.js script in the shortcut.

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless.



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks


Previous post: Locking a Windows Session
Next post:FIF Isn't Forth


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

Along Came AWK

Screen Captures with Java and Clojure

Hiding Batch File Console Windows

Thwarting HTTP Referer Trackbacks

Scott Ballantyne: Blazin' Into Forth

A Simple ROT13 Macro

Locking a Windows Session

Pi Day Meets the HTML5 Canvas

An Interview with the Author of the French Silk Assembler

A Command-Line CD Tray Opener


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service