How can I use a script to lock the taskbar?

Source: Internet
Author: User

CopyCode The Code is as follows: HKEY_CURRENT_USER = & h80000001

Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")

Strkeypath = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced"
Valuename = "taskbarsizemove"
Dwvalue = 0

Objreg. setdwordvalue HKEY_CURRENT_USER, strkeypath, valuename, dwvalue

Facts have proved that you can lock or unlock the taskbar by switching a value in the registry. More specifically, you can switch the registry value SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced \ taskbarsizemove. Set this value to 0 to lock the taskbar. Set it to 1 to unlock the taskbar. As you might expect, to lock the taskbar, our script only needs to set the value of taskbarsizemove to 0, and everything is fine.

To implement this function, the script first defines a constant named HKEY_CURRENT_USER and sets its value to & h80000001; we will use this constant to indicate which registry Configuration unit the script will process. (The Task Bar is locked or unlocked for a single user .) Then, we use the following two lines of code to connect to the WMI Service on the local computer:

Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")

But don't worry; you are not limited to running this script on the local machine. It is easy to modify the script to run in a remote computer environment. Therefore, you only need to assign the computer name to the variable strcomputer. For example, the following code binds a WMI Service to a computer named atl-ws-01:

Strcomputer = "atl-ws-01"
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")

Is it easier to move to or from an office and manually lock the taskbar between 300 and 400 computers? We cannot come down to this conclusion, but it sounds easier, isn't it?

After connecting to the WMI Service, you can assign the Registry path (Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced) to a variable named strkeypath. Then assign the actual registry value (taskbarsizemove) We want to change to a variable named valuename. Finally, assign the value 0 to a variable named dwvalue. This variable represents the value that we want to assign to taskbarsizemove.

Note: What if we want to unlock the taskbar instead of locking it? No problem; you only need to assign value 1 to dwvalue.

Now all we need to do is call the setdwordvalue method and pass the constant HKEY_CURRENT_USER and variable strkeypath, valuename, and dwvalue as parameters:

Objreg. setdwordvalue HKEY_CURRENT_USER, strkeypath, valuename, dwvalue

This is done, but you may have to log out first and then log on again to make the change take effect. Therefore, you may want to add the code to the logout script. This will automatically take effect when the user logs out. The taskbar will be locked upon next login.

Our scripting experts were eager to compile such a script 10 years ago. Of course, even so, he still has to copy the script to a floppy disk, and then carry the floppy disk around the office. In addition, there were neither Windows Script Host nor WMI at that time, so it was still difficult to run the script. But these are just trivial things. Our scripting experts will find a way to avoid such small problems.

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.