Enabling Clock at User Logon

I had what seemed like a straight forward scenario which turned out quite the opposite, basically I wanted to enable the clock for all of the users logging into a machine.  Great I thought, no problem, just hack in a StuckRects2 Settings registry value which has the clock enabled at logon right?

Then, looking closely I really didn’t want to affect other settings such as if the taskbar is always on top, small or large start menu icons are being used etc…  This is when things got interesting because the StuckRects2 Settings value is not exactly readable…

So if you look at a StuckRects2 Settings value, you’ll see it’s a registry value which looks like this 28 00 00 00 ff ff ff ff 06 00 00 00 03 00 00 00 44 00 and so forth…  Each of these numbers are actually binary, so for example 00 = 00000000 whereas FF = 11111111 and everything in between.  Finally to top it all off, the bits in each binary number control different elements of different parts of the shell.

So let me explain.  I found that the 9th binary number is actually what controls the Windows taskbar, but that’s not enough – I needed to understand what each bit did, so I changed the bits one by one until I had them all documented – here is what I found, I’ll write them top down representing left to right…

1 – Toggles the Previews (Vista only – doesn’t seem to do anything in XP)

1 – Toggles the Display Power option

1 – Toggles the Display Network option

1 – Toggles the Display Volume option

1 – Toggles the Display Clock option

1 – Toggles the Use Small Icons option

1 – Toggles the Keep Taskbar On Top option

1 – Toggles the Auto Hide Taskbar option

So if you said you wanted to toggle the Display Power and Display Clock options only, you would use 01001000 which you would then convert into hexadecimal (72) which would then become your 9th binary number…

That’s cool and all but still not enough – I still needed a way to read the binary numbers modify them and write them back.  VBScript doesn’t allow you to read binary registry data, but WMI does – so getting the number wasn’t a problem…

const HKCU = &H80000001

dim oWMIReg

set oWMIReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\.rootdefault:StdRegProv")

dim iValueArray()

oWMIReg.GetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", iValueArray

The above script will get the collection of settings from StuckRects2 Settings and store them in the array iValueArray.  From here we can query the 9thbinary number, just remember it’s a zero-based array so you actually count 0, 1, 2 etc…

Msgbox iValueArray(8)

This line will print the decimal (not hex) representation of the binary number.

Now you can write a value back if you wish like this…

iValueArray(8) = 114

oWMIReg.SetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", iValueArray

OK, so that takes care of patching that single set of binary bits, but what about the individual settings within that binary number – we want to preserve them too.  Now this so soooo cool and I didn’t know VBScript did this at first.  In VBScript you can actually AND, OR and NOT binary numbers.  If you don’t know AND, OR and NOT go to Wikipedia as this is already getting too long and I’m boring you enough, but needless to say, in the script I could AND or AND and OR my current binary number with a new one containing the flipped bit to turn on the clock, this is done like this…

To enable the clock and leave everything else as it was

iValueArray(8) = (iValueArray(8) AND &h07) OR &h08

To disable the clock and leave everything else as it was

iValueArray(8) = (iValueArray(8) AND &h07)

So my final script to enable just the clock bit looked like this:

const HKCU = &H80000001

dim oWMIReg

set oWMIReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\.rootdefault:StdRegProv")

dim iValueArray()

oWMIReg.GetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", iValueArray

iValueArray(8) = (iValueArray(8) AND &h07) OR &h08

oWMIReg.SetBinaryValue HKCU, "SoftwareMicrosoftWindowsCurrentVersionExplorerStuckRects2", "Settings", iValueArray

All I did now was make this happen at login and it worked like a charm. Anyway, this has given me many more thoughts such as deciphering the hide-drives binary value and doing something clever instead of a fixed static 111111 etc…

 

From: Deciphering STUCKRECTS2

Leave a Reply

Your email address will not be published. Required fields are marked *