VB Script to Set a Screensaver on XP PCs

Posted on 2009-02-18
Last Modified: 2012-08-13
I am looking for a VB Script that will allow me to set the screensaver for the current user to a file located in the windows\system32 folder on XP PCs.
Question by:zabac
    LVL 38

    Accepted Solution

    Paste the script below into a text file with a .vbs extension.  Customize the value of the strFile variable with the name of the desired .scr file.  Running the script will change the screen saver setting in the registry.

    It's usually easier to manage this kind of thing through the Group Policy node User Configuration\Administrative Templates\Control Panel\Display.

    Const HKEY_CURRENT_USER = &H80000001
    strFile = "logon.scr"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strSystemFolder = objFSO.GetSpecialFolder(1)
    Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
    strKeyPath = "Control Panel\Desktop"
    strValueName = "SCRNSAVE.EXE"
    strValue = strSystemFolder & "\" & strFile
    objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

    Open in new window

    LVL 7

    Assisted Solution

    You'll also probably want to explicitly set the time delay for the screensaver as well to override anything the user may have set (or override the default 10 minutes) with a delay of your choosing.

    Using Shift-3's code format for consistency, you can add the following to it:
    'scrnsaveDelay's value is based on number of seconds,
    'eg. 120 seconds = 2 minutes.
    Const scrnsaveDelay = 120
    strTimer = "ScreenSaveTimeOut"
    objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strTimer, scrnsaveDelay

    Open in new window


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now