Use VBScript to modify the wait time length for screen protection _vbs

Source: Internet
Author: User
Ask:
Hey, scripting guy!. Can I use a script to modify the length of the wait time for screen protection on your computer?
--JN
For:
Hi, JN. For some reason, Microsoft's scripting technology has some drawbacks in terms of Windows settings and components, such as screen saver, wallpaper, taskbar, and Start menu, and so on. 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, then? Frankly speaking, we don't know;
Thankfully, most of these values are stored in the Windows registry, and as long as they are stored in the registry, you can write scripts to manage them. Screen saver is no exception. Open Regedit, let's look inside the 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 time that screen protection waits. By default, this value is set to 600 seconds, or 10 minutes.
So, how do you change this value? You can change the wait time to 5 minutes (300 seconds) by using the following script:
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 do this, we first create a constant named HKEY_CURRENT_USER and set its value to &H80000001; this tells WMI registry provider that we are working on the HKEY_CURRENT_USER part of the registry. If we're going to handle HKEY_LOCAL_MACHINE, then we need to set the constant to &H80000001; set the constant to &h80000003 to handle the HKEY_USERS.
Because we execute this script on the local computer, we set the variable strComputer to a point (the shortcut to the local computer in WMI). The beauty of the registry provider is that it works on a remote computer and that performance is as good as on the local computer. So if you want to change the screen saver wait time on a remote computer, simply set the StrComputer value to the name of that computer.
Since then, we have connected to the WMI service and specified the registry path (Control Panel\Desktop). Next we'll call the CreateKey method. This is for the sake of insurance. Because if the registry key we are looking for does not exist, then CreateKey creates the registry key. If the registry key already exists, then CreateKey will retain the registry key.
After specifying the registry value name (ScreenSaveTimeOut) to change and the new value (300), we then use the SetStringValue method to change the wait time to 300 seconds.
It's not too bad, is it? For more information about the registry provider--perhaps the least common of all WMI providers--See the "registry" chapter in the Microsoft Windows 2000 Scripting Guide. and visit the infamous Tweakomatic, this amazing utility can write scripts that can read and write to the registry. In order to glory from the traditional business, it uses the name of Tweakomatic, which does a lot of good.
Incidentally, here is another more useful screensaver script that ensures that screen savers are 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
You see, how interesting is the registry script writing?! Tweakomatic There are other scripts that you can use to manage your screen saver, Start menu, taskbar, Windows Explorer folder settings, and more. If you're 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.