Wednesday, November 4, 2009

Desktop Settings

As an IT Consultant I typically logon to many different servers and workstations and have found myself adjusting the default desktop settings hundreds, maybe thousands, of times to set my preferences. I absolutely hate the default settings provided by Microsoft and can't stand doing even simple file management tasks with those settings. Who the heck thought Large Icons in folders was a good idea anyway? And hiding file extensions has got to be the stupidest idea anyone ever thought of. Anyone remember annakournikova.jpg.vbs? Thanks, Microsoft for making our users even stupider.

Anyway I spent some time building a VBS script to set all of my personal preferences in one shot. I store this file on my web server as a .txt file in case I'm at a client who has VBS downloads disabled, which is a pretty good idea in general. I just memorize the URL, download it to the desktop, change the file extension to .vbs, and run it. Some of the settings require explorer.exe to be closed so rather than kill the process with Task Manager, there is an easier way that lets it shut down cleanly. First open a cmd window or Task Manager, then go to Start, Shutdown, hold down Ctrl-Shift-Alt, and click Cancel. This will shut down explorer.exe and allow you to make the modifications. Using cmd or Task Manager's File | Run command, type in the path to the VBS file and run it. Then you can launch explorer.exe and view your changes.

Pretty much all the settings modify the current user profile so it's safe to use on a machine that is used by someone else if you're logging on with different credentials. It does some fun things like telling IE that it has already run the welcome screen, sets my tab defaults and home page, disables the Outlook tray notifications, expands all of the Start Menu folders, sets Explorer to List View, increases the taskbar to two lines and turns on the clock (Terminal Servers hide the clock by default), lock the taskbar, shows the hidden desktop icons, gets rid of that stupid Language Bar, and removes the lame default sorting of the Start Menu.

Most of the registry keys are pretty self-explanatory but some need clarification. StuckRects2 is a binary value that controls the taskbar, clock, and some other settings. I just copied the values from a system that is set exactly the way I want it and hardcoded the hex values into aStuckRects. Streams is another binary value that controls the folder view customizations (I like List view by default). Deleting a registry key with subkeys is not possible with RegDelete so there is a function to help with that. I'm sure there are a lot of annoying startup programs that I'm missing, I add them as I come across them.

Here is the current version of my VBS file as of this posting. You can also download my latest version at ac64.com.

'Create Objects
Set oWSH = CreateObject("WScript.Shell")
Set oNet = CreateObject("WScript.Network")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

'Define constants and values for long registry keys
Const HKEY_CURRENT_USER = &H80000001
sUsername = LCase(oNet.Username)
sOLTray03 = "HKCU\SOFTWARE\Microsoft\Office\11.0\Outlook\Display Types\Balloons"
sOLTray07 = "HKCU\SOFTWARE\Microsoft\Office\12.0\Outlook\Display Types\Balloons"
sRunU = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
sRunM = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
sIE = "HKCU\Software\Microsoft\Internet Explorer"
sExp = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer"
sStream = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Streams"
sStuckRects = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2"

'Set personal settings
aStream = Array(&H08,&H00,&H00,&H00,&H03,&H00,&H00,&H00,_
&H00,&H00,&H00,&H00,&HE0,&HA5,&H1F,&H0E,_
&H73,&H35,&HCF,&H11,&HAE,&H69,&H08,&H00,_
&H2B,&H2E,&H12,&H62,&H04,&H00,&H00,&H00,_
&H01,&H00,&H00,&H00,&H43,&H00,&H00,&H00)
aStuckRects = Array(&H28,&H00,&H00,&H00,&HFF,&HFF,&HFF,&HFF,_
&H02,&H00,&H00,&H00,&H03,&H00,&H00,&H00,_
&H3C,&H00,&H00,&H00,&H37,&H00,&H00,&H00,_
&HFE,&HFF,&HFF,&HFF,&HEB,&H02,&H00,&H00,_
&H02,&H05,&H00,&H00,&H22,&H00,&H00,&H00)
sHomePage = "http://www.google.com"

On Error Resume Next

'Outlook Settings
oWSH.RegWrite sOLTray03 & "\Exchange", 0, "REG_DWORD"
oWSH.RegWrite sOLTray03 & "\NetConn", 0, "REG_DWORD"
oWSH.RegWrite sOLTray03 & "\NetWarn", 0, "REG_DWORD"
oWSH.RegWrite sOLTray07 & "\Exchange", 0, "REG_DWORD"
oWSH.RegWrite sOLTray07 & "\NetConn", 0, "REG_DWORD"
oWSH.RegWrite sOLTray07 & "\NetWarn", 0, "REG_DWORD"

'Windows Explorer/Desktop Settings
oWSH.RegWrite sExp & "\Advanced\EnableBalloonTips", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_AdminToolsRoot", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\StartMenuAdminTools", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_LargeMFUIcons", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_NotifyNewApps", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowHelp", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowMyComputer", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowControlPanel", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowMyDocs", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowMyMusic", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowMyPics", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowNetConn", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowNetPlaces", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowPrinters", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\Start_ShowRun", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\TaskbarSizeMove", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\StartMenuFavorites", 2, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\ServerAdminUI", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\Advanced\HideFileExt", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\Desktop\CleanupWiz\NoRun", 1, "REG_DWORD"
oWSH.RegWrite sExp & "\HideDesktopIcons\NewStartPanel\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\HideDesktopIcons\NewStartPanel\{450D8FBA-AD25-11D0-98A8-0800361B1103}", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\HideDesktopIcons\NewStartPanel\{208D2C60-3AEA-1069-A2D7-08002B30309D}", 0, "REG_DWORD"
oWSH.RegWrite sExp & "\HideDesktopIcons\NewStartPanel\{871C5380-42A0-1069-A2EA-08002B30309D}", 0, "REG_DWORD"
oWSH.RegWrite "HKCU\Software\Microsoft\CTF\LangBar\ShowStatus", 3, "REG_DWORD"
oReg.SetBinaryValue HKEY_CURRENT_USER, sStream, "Settings", aStream
oReg.SetBinaryValue HKEY_CURRENT_USER, sStuckRects, "Settings", aStuckRects
oWSH.RegWrite sIE & "\Main\StatusBarOther", 1, "REG_DWORD"

'Internet Explorer Settings
oWSH.RegWrite sIE & "\Main\Start Page", sHomePage, "REG_SZ"
oWSH.RegWrite sIE & "\Main\AlwaysShowMenus", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\Main\RunOnceHasShown", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\Main\IE8RunOncePerInstallCompleted", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\Main\IE8TourShown", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\Main\IE8RunOnceLastShown", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\Groups", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\NewTabPageShow", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\OpenInForeground", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\PopupsUseNewWindow", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\ShowTabsWelcome", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\UseHomepageForNewTab", 1, "REG_DWORD"
oWSH.RegWrite sIE & "\TabbedBrowsing\WarnOnClose", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\PhishingFilter\Enabled", 0, "REG_DWORD"
oWSH.RegWrite sIE & "\PhishingFilter\EnabledV8", 0, "REG_DWORD"
oWSH.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\IEHarden", 0, "REG_DWORD"
oWSH.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\IEHardenIENoWarn", 0, "REG_DWORD"

'Delete registry entries including annoying startup programs
DeleteRegEntry HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu2"
DeleteRegEntry HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\StartMenu"
DelReg "\MsnMsgr"
DelReg "\AdobeUpdater"
DelReg "\Adobe Reader Speed Launcher"
DelReg "\DVDLauncher"
DelReg "\SunJavaUpdateSched"
DelReg "\My Web Search Bar Search Scope Monitor"
DelReg "\MyWebSearch Email Plugin"
DelReg "\iTunesHelper"
DelReg "\QuickTime Task"
DelReg "\HP Software Update"
DelReg "\HPUsageTracking"
DelReg "\BrStsWnd"
DelReg "\LXCYCATS"

Sub DelReg(key)
oWSH.RegDelete sRunU & key
oWSH.RegDelete sRunM & key
End Sub

Function DeleteRegEntry(sHive, sEnumPath)
' Attempt to delete key. If it fails, start the subkey enumeration process.
lRC = oReg.DeleteKey(sHive, sEnumPath)

' The deletion failed, start deleting subkeys.
If (lRC <> 0) Then
lRC = oReg.EnumKey(sHive, sEnumPath, sNames)

For Each sKeyName In sNames
If Err.Number <> 0 Then Exit For
lRC = DeleteRegEntry(sHive, sEnumPath & "\" & sKeyName)
Next

' At this point we should have looped through all subkeys, trying to delete the registry key again.
lRC = oReg.DeleteKey(sHive, sEnumPath)
End If
End Function

No comments:

Post a Comment