Copy the codeThe 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
HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
It turns out that the taskbar can be locked or unlocked by switching a value in the registry; rather, it is by switching 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 simply sets the value of TaskBarSizeMove to 0 and everything goes well.
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 hive the script is going to handle. (The locking and unlocking taskbars are both done for a single user.) We then 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're not limited to running the script on the machine. Instead, it is easy to modify the script to run in a remote computer environment. To do this, just assign the name of the computer to the variable strComputer. For example, the following code will be bound to the WMI service on a computer named atl-ws-01:
strComputer = "atl-ws-01"
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Would this be easier than going back and forth between offices and manually locking the taskbar on 300 to 400 computers? We can't draw this conclusion exactly, but it does sound easier, doesn'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 we want to assign to TaskBarSizeMove.
Note: What if we want to unlock the taskbar instead of locking it? No problem; just assign the value 1 to dwValue.
Now all we have to do is call the SetDWORDValue method, passing the constant HKEY_CURRENT_USER and the variable strKeyPath, ValueName and dwValue as parameters:
HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
This is done, but you may have to log out first and then log in again before this change can actually take effect. Therefore, you may want to add that code to the logout script; this way the changes will take effect automatically when the user logs out. The next time the user logs in, the taskbar will be locked.
How desperately our scripting expert is to write such scripts 10 years ago. Of course, even so, he still had to copy the script to a floppy disk and take it with him to and from the offices. In addition, there was neither Windows Script Host nor WMI at that time, so it was still difficult to run the script. But these are just trivial things, and our script experts will inevitably find a way to avoid such minor problems.