How Can I Configure the Screensaver Used When No One is Logged On to a Computer?

ScriptingGuy1

Hey, Scripting Guy! Question

Hey, Scripting Guy! I recently downloaded your Script Center screensaver, and it works great as long as someone is logged on to the computer. However, when no one is logged on the computer uses a different screensaver. How can I get the computer to use the Script Center screensaver when no one is logged on?

— RF

SpacerHey, Scripting Guy! AnswerScript Center

Hey, RF. You know, it occurred to us that you might be trying to pull a fast one on the old Scripting Guys. For example, how do we know it’s really our screensaver that you want to run when no one is logged on to the computer? Maybe this is just a way to flatter the Scripting Guys into answering your question, and then, once we do so, you’ll go out and install some other scripting-related screensaver as the default. RF, RF: did you really believe that the Scripting Guys are so shallow that we’d succumb to cheap flattery like that?

Well you should have, because we are:

Const HKEY_USERS = &H80000003

strComputer = “.”

Set objReg = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “.Default\Control Panel\Desktop” ValueName = “SCRNSAVE.EXE” strValue = “C:\WINDOWS\System32\Script Center.scr”

objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

As you can see, this is a WMI script for changing the registry. It’s very similar to the many other registry-modifying scripts we’ve shown you in the past, albeit with one unique twist. In our previous scripts we’ve always started out by defining a constant that tells that script that we want to work with either the HKEY_CURRENT_USER or the HKEY_LOCAL_MACHINE registry hive. And there’s good reason for that: we want whatever modification we’re making to apply to the current user or to the computer itself. Ah, but notice the first line of this script:

Const HKEY_USERS = &H80000003

That’s the secret right there: this time we want to work with the HKEY_USERS registry hive. Among other things, the HKEY_USERS hive provides you with a place to configure settings that, in lieu of any specific user, apply to anyone who logs on to the computer. In other words, if you configure a screensaver in HKEY_USERS, that screensaver is the default that will apply to any new user who logs on to the computer. (And that’s the screensaver that will continue to apply unless the user specifically configures a different screensaver.) Likewise, when no one is logged on to the computer that’s the screensaver that will be used.

Cool, huh? Incidentally, this is also where you can configure the wallpaper that appears at the logon screen; just set the registry value HKEY_USERS\.Default\Control Panel\Desktop\Wallpaper to the appropriate file path. Something like this:

Const HKEY_USERS = &H80000003

strComputer = “.”

Set objReg = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “.Default\Control Panel\Desktop” ValueName = “Wallpaper” strValue = “C:\WINDOWS\System32\Script Center.bmp”

objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

After defining our constant we next connect to the WMI service on the local computer (although this script works equally well against remote computers). We then assign values to three different variables:

•

strKeyPath – The path to the registry key within HKEY_USERS. In this case, that’s .Default\Control Panel\Desktop.

•

ValueName – The name of the registry value we want to change (SCRNSAVE.EXE).

•

strValue – The new value to be assigned to SCRNSAVE.EXE. In this script, that’s the full path to the screensaver.

All that’s left to do now is call the SetStringValue method (passing along the constant HKEY_USERS and our three variables as parameters) and we’re done:

objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

If you log off and wait a few minutes the Script Center screensaver should kick in. (Well, assuming that the registry value ScreenSaveActive is set to 1; if it’s set to 0, that means the screensaver has been disabled.)

See how easy that is? And no, we don’t mean the script (although that’s pretty easy, too); we mean how easy it is to get your question answered, provided you word that question in the right way, of course. Like they say, flattery will get you anywhere.

0 comments

Discussion is closed.

Feedback usabilla icon