How Can I Use a Script to Lock the Taskbar?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I use a script to lock the Taskbar?

— RK

SpacerHey, Scripting Guy! AnswerScript Center

Hey, RK. One of the Scripting Guys was a computer support person at the University of Washington when Windows 95 was released. This Scripting Guy has two lasting memories of those days. For one, he remembers having to install both Windows 95 and Microsoft Office on several hundred machines, back when that meant using 9 or 10 floppy disks to install Windows and another 14 or 15 to install Office. (CD drives? Network connections? This was back in the dark ages of computing, especially for people in the academic world.)

As you might expect, it took a couple of months for this Scripting Guy to get Windows and Office installed on all the department computers. Which leads into his second lasting memory of the Windows 95 era: spending the next few months going around from office to office helping people realign, resize, and lock down their Taskbars. Back in those days the Taskbar was not locked down by default; as a result, the UW ended up with Taskbars everywhere: docked on the right side, docked on the left side, docked on top of the screen. People resized their Taskbars so large that the toolbar filled up half the screen, or so small that they didn’t even know they had a Taskbar any more. For two months (although it seemed like two years) this Scripting Guy’s primary job was to reconfigure and lock down Taskbars. Day after day after day.

And, yes, coincidentally enough that was about the same time he began to wonder if maybe there might something else he could do with his life than be a computer support person.

Our poor little Scripting Guy; if only he’d had a script like this one at his disposal:


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

As it turns out, the Taskbar can be locked and unlocked by toggling a value in the registry; in particular, by toggling the registry value Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskBarSizeMove. Set this value to 0 and the Taskbar will be locked; set this value to 1 and the Taskbar will be unlocked. As you might expect, in order to lock the Taskbar our script does nothing more than simply set the value of TaskBarSizeMove to 0.

To accomplish this feat the script starts out by defining a constant named HKEY_CURRENT_USER and setting the value to &H80000001; we’ll use this constant to tell the script which registry hive to work with. (Locking and unlocking the Taskbar is done on a per-user basis.) We then use these 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 this script locally. Instead, the script can easily be modified to work against a remote computer. To do that, simply assign the name of the computer to the variable strComputer. For example, this code binds to the WMI service on a computer named atl-ws-01:

strComputer = “atl-ws-01”
Set objReg = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

Is that easier than walking around and manually locking the Taskbar on 300-400 computers? We can’t say for sure, but it definitely sounds easier, doesn’t it?

After making the connection to the WMI service we assign the registry path (Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced) to a variable named strKeyPath. We then assign the actual registry value (TaskBarSizeMove) we want to change to a variable named ValueName. Finally, we assign the value 0 to a variable named dwValue. This variable represents the value we want assigned to TaskBarSizeMove.

Note. What if we wanted to unlock the Taskbar instead of locking it? No problem; we’d just assign dwValue the value 1.

All we have to do now is call the SetDWORDValue method, passing as parameters the constant HKEY_CURRENT_USER and the variables strKeyPath, ValueName, and dwValue:

objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

That will do the trick, although you’ll probably have to log off and then log back on before the change actually takes effect. Because of that you might want to add this code to a logoff script; that way the change will automatically take place when the user logs off. The next time the user logs on the Taskbar will be locked.

And, yes, our Scripting Guy desperately wishes he would have written this script 10 years ago. Of course, he still would have had to copy the script onto a floppy disk and then cart that floppy around from office to office. In addition, neither Windows Script Host nor WMI existed back then, which might have made it a bit more difficult to get the script to run. But those are just details, and surely our Scripting Guy would have figured out a way to sidestep minor issues like that.

Good point: not this Scripting Guy. But maybe someone else would have been able to suggest something.