Use Vbscript to modify the wait time for Screen Protection

Source: Internet
Author: User

Q:
Hi, scripting guy! Can I use a script to modify the wait time of screen protection on a computer?
-- JN
A:
Hi, JN. For some reason, Microsoft's script technology is insufficient in terms of Windows Settings and components, such as screen protection, wallpaper, taskbar, and start menu. You can use WMI (especially the win32_desktop class) to read these values, but you cannot use the win32_desktop class (or any equivalent class or object) to modify these values. Why? Honestly, we don't know either;
Fortunately, most of these values are stored in the Windows registry, and as long as these values are stored in the registry, you can write scripts to manage them. Screen Protection Program Is no exception. Open regedit. Let's take a look at HKEY_CURRENT_USER. In the Control Panel \ Desktop item, you will see several registry values related to the screen saver, including screensavetimeout. As you may have guessed, This is the registry value that determines the length of the Screen Protection wait time. By default, this value is set to 600 seconds, that is, 10 minutes.
So how can we change this value? You can use the following script to change the wait time to 5 minutes (300 seconds ):
HKEY_CURRENT_USER = & h80000001
Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")
Strkeypath = "Control Panel \ Desktop"
Objreg. createkey HKEY_CURRENT_USER, strkeypath
Valuename = "screensavetimeout"
Strvalue = "300"
Objreg. setstringvalue HKEY_CURRENT_USER, strkeypath, valuename, strvalue
To achieve this, we first create a constant named HKEY_CURRENT_USER and set its value to & h80000001; this tells the WMI registry provider that we are processing the HKEY_CURRENT_USER Section of the Registry. If we want to process HKEY_LOCAL_MACHINE, we need to set the constant to & h80000001; and set the constant to & h80000003, then we can process HKEY_USERS.
Since we execute this script on the local computer, we set the variable strcomputer to a vertex (representing the shortcut of the Local Computer in Wmi ). The good thing about the Registry provider is that it can work on a remote computer and has the same performance as on a local computer. Therefore, if you want to change the Screen Protection wait time on the remote computer, you only need to set the value of strcomputer to the name of that computer.
From this point on, we connect to the WMI Service and specify the Registry path (Control Panel \ Desktop ). Next we will call the createkey method. This is for the sake of insurance. Because if the registry key we are looking for does not exist, createkey creates this registry key. If the registry key already exists, the createkey retains the registry key.
After specifying the Registry Value Name (screensavetimeout) and the new value (300), we will use the setstringvalue method to change the wait time to 300 seconds.
Not too bad, right? For more information about the Registry provider, which may be the least commonly used among all WMI providers, see the Registry chapter in the Microsoft Windows 2000 script guide. And access the well-known tweakomatic. This amazing utility can be used to write scripts that can perform read and write operations on the registry. To draw light from traditional businesses, it uses the tweakomatic name, which is indeed advantageous.
By the way, the following is another useful Screen Saver script, which ensures that the Screen Saver is password protected:
HKEY_CURRENT_USER = & h80000001
Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")
Strkeypath = "Control Panel \ Desktop"
Objreg. createkey HKEY_CURRENT_USER, strkeypath
Valuename = "ScreenSaverIsSecure"
Strvalue = "1"
Objreg. setstringvalue HKEY_CURRENT_USER, strkeypath, valuename, strvalue
How interesting is registry script writing ?! Tweakomatic has other scripts for managing screen saver, Start Menu, taskbar, Windows Resource Manager folder settings, and more. If you are looking for ways to manage common desktop settings, this is a good place to start working.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.