Jim Lawless' Blog


Invoking the Default Windows Screen-Saver

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

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.

del_icio_us Save to del.icio.us
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


Search this Blog (and site)

Search this Site with PicoSearch


Subscribe to this Blog

 Subscribe!


Contact Me

Email: jimbo@radiks.net


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

Mad Schemes : Learning Lisp via SICP

Auto Save Clipboard Images Redux

Extending SpiderMonkey JavaScript on Windows

Rhino JavaScript to EXE with launch4j

Compiling Rhino JavaScript to Java

Directory Traversal in Rhino JavaScript

Taking Shape

We've Moved!


Popular Posts

A Command-Line MP3 Player for Windows

Auto Save Images from the Clipboard

Java in a Windows EXE with launch4j

An Interview with Tom Zimmer: Forth System Developer

Setting Windows Console Text Colors in C


Random Posts

An Interview with Tom Zimmer: Forth System Developer

My Foray into Shareware

Embedding JavaScript in a Batch File

Learning Z-80 Assembly Language on the TRS-80

COM Scripting in C by way of JavaScript

Extending SpiderMonkey JavaScript on Windows

Charging by the Byte

Obfuscated Ruby

Mad Schemes : Learning Lisp via SICP

A Quine in C


Full List of Posts

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


Blogroll

MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer