The Deployment Guys

Helping to deploy your world automagically...

Useful Script Number 3 - Turning the Windows Vista Sidebar On and Off

Useful Script Number 3 - Turning the Windows Vista Sidebar On and Off

  • Comments 1
  • Likes

One of the things that you may want to do during a build or deployment process is turn off the Windows Vista sidebar for the period of the process and then turn it back on again at the end. This can be for a number of reasons including that you don't want the sidebar interfering with any of you tasks. Recently Richard Trusson and I found that when the Office 2007 SP1 updates were added to a build, an number of VB error output box's popped up as the updates were being applied - we traced this back to an issue with the sidebar and although this didn't stop the build process, it was messy - so we went about putting together the script below to turn on/off the side bar.

The script accepts an input on the command line /state: which can be either On or Off (for example /state:on or /state:off). The script then uses WMI to stop or start the sidebar.exe program - and iff the state is set to off, then sets the registry to disable the sidebar so it doesn't pop up if the machine is re-booted during the build process.

<job id="zCFG-SidebarState">
    <script language="VBScript" src="ZTIUtility.vbs"/>
    <script language="VBScript">
' //***************************************************************************
' // ***** Script Header *****
' //
' // Solution: Solution Accelerator for Business Desktop Deployment
' // File: zCFG-SidebarState.wsf
' //
' // Purpose: Template
' //
' // Usage: cscript zCFG-SidebarState.wsf /State:[On|Off][/debug:true]
' //
' // Customer Build Version: 1.0.0
' // Customer Script Version: 1.0.0
' // Customer History:
' //
' // ***** End Header *****
' //***************************************************************************
'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------
Option Explicit
Dim iRetVal
'//----------------------------------------------------------------------------
'// End declarations
'//----------------------------------------------------------------------------
'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------
'On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
'On Error Goto 0
'//---------------------------------------------------------------------------
'//
'// Function: ZTIProcess()
'//
'// Input: None
'//
'// Return: Success - 0
'// Failure - non-zero
'//
'// Purpose: Perform main ZTI processing
'//
'//---------------------------------------------------------------------------

Function ZTIProcess()
     iRetVal = Success
     ZTIProcess = iRetVal

'//----------------------------------------------------------------------------
'// custom code
'//

Dim sSName, iZTIRetValue,sSideBarState,stemp
DIM strComputer,objWMIService,colProcessList,objProcess,intRC

sSName=oUtility.ScriptName
iZTIRetValue=1

oLogging.CreateEntry sSName & ": Starting actions************************************************************ ",LogTypeInfo

'Check to see if the state is set on the command line.
'If not error out as this is mandatory
sSideBarState = oUtility.Arguments("State")

Select Case UCase(sSideBarState)
Case "ON"
    oLogging.CreateEntry sSName & ": The sidebar state has been requested to be changed to : " & sSideBarState,LogTypeInfo
    'now lets try to restart the sidebar.
    iZTIRetValue=oShell.Exec("c:\program files\windows sidebar\sidebar.exe").status
    if iZTIRetValue > 0 then
        oLogging.CreateEntry sSName & ": Could not start sidebar",LogTypeError
        ZTIProcess=90
        Exit Function
    Else
        oLogging.CreateEntry sSName & ": Started sidebar succesfully",LogTypeInfo
    End If
    stemp=SetReg("0")
    If stemp<>0 Then
        ZTIProcess=80
        Exit Function
    End If

Case "OFF"
    oLogging.CreateEntry sSName & ": The sidebar state has been requested to be changed to : " & sSideBarState,LogTypeInfo

    'Close the Sidebar
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'sidebar.exe'")
    For Each objProcess in colProcessList
        intRC=objProcess.Terminate()
        If intRC = 0 Then
            oLogging.CreateEntry sSName & ": Sidebar process closed",LogTypeInfo
        Else
            oLogging.CreateEntry sSName & ": Could not kill the Sidebar process",LogTypeError
            ZTIProcess=1
            Exit Function
        End If
    Next
    'now set the registry
    stemp=SetReg("1")
    If stemp<>0 Then
        ZTIProcess= 70
        Exit Function
    End If

Case Else
    oLogging.CreateEntry sSName & ": The sidebar state request is unrecognised. Task is terminating",LogTypeInfo
    ZTIProcess=99
    Exit Function

End Select

oLogging.CreateEntry sSName & ": Completed actions************************************************************ ",LogTypeInfo

ZTIProcess=0
End Function

'//
'// End Custom Code
'//-----------------------------------------------------------------------------

Function SetReg(dwValue)
Dim objReg, ValueName, strKeyPath
Const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CURRENT_USER = &H80000001
    Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Windows\Sidebar"
    objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
    ValueName = "TurnoffSidebar"
    objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
    If Err<>0 Then
        oLogging.CreateEntry "Unable to set registry value of " & ValueName & " to " & dwValue & ". Terminating",LogTypeError
        SetReg=10
        Exit Function
    End If
    oLogging.CreateEntry "Set registry value of " & ValueName & " to " & dwValue & ".",LogTypeInfo
    Set objReg = Nothing

    SetReg=0
End Function
    </script>
</job>

 

You can add this script as a task sequence item at the start of the State Restore phase with the /state:off switch and then add a second task towards the end of your task sequence with the /state:on switch

image

 

You can download the script from the Deployment Guys SkyDrive:

This post was contributed by Richard Smith and Richard Trusson - Senior Consultants with Microsoft Services, UK.

  • I think that CS3 causes the same problems with the sidebar.  I don't know for sure, but I used a little simpler tact to closing my sidebar during my CS3 install.  I just used "taskkill /F /IM sidebar.exe /T".  :)  Of course the sidebar comes back on the next reboot, but I never would have been able to write that script like ya'll did, so I just did what I could think ok.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment