Monday, April 14, 2008

DST2008 script - could be used for other things

Basically i wrote this script to address an issue our parent company was having with incompletely patched machines. By opening the clock and unchecking and then checking back the Automatically adjust clock for daylight saving changes the issue is resolved as the time zone gets reapplied properly. The problem is that if a user has no admin rights, youre pretty much screwed. This script will also run the Outlook mailbox TZMove tool. Yes you could run it centrally. But how do you know which user's were patched before the existing appointments got created?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=DST2008.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
AutoItSetOption ("RunErrorsFatal", 0)
AutoItSetOption ("TrayIconHide",1)
call ("StartSequence")
 
Func StartSequence()
    if $CmdLine[$CmdLine[0]] = "" then 
        Exit
    Else
        Select
            case $CmdLine [1] = "/uninstall"
                if not IsAdmin() then Exit
                call("uninstall")
                
            case $CmdLine [1] = "/install" 
                $DS = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "DaylightStart")
                if $DS = "00000300020002000000000000000000" then
                    $log = FileOpen("\\NYITSUPPORT\DST2008\LOGS\" & @ComputerName & ".log",9)
                    FileWriteLine($log, @CRLF & "DaylightStart is proper. Nothing done " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN)
                    FileClose($log)
                    Exit
                Else
                    if not IsAdmin() then Exit
                    Call ("Install")
                EndIf
 
            case $CmdLine [1] = "/tzmove"
                call ("tzmove")
            case Else
                Exit
                
        EndSelect
    EndIf
EndFunc
 
func tzmove()
    RunWait('"C:\Program Files\Microsoft Office\Office12\Office Outlook Time Zone Data Update Tool\tzmove.exe" /quiet',"",@SW_HIDE)
    $log = FileOpen("\\NYITSUPPORT\DST2008\LOGS\" & @UserName & "\" & @ComputerName & ".log",9)
    FileWriteLine($log, @CRLF & "TZMove executed " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN)
    FileClose($log)
    FileCopy(@TempDir & "\Outlook Time Zone Update.log", "\\NYITSUPPORT\DST2008\LOGS\" & @UserName,9)
EndFunc
 
Func Install()
    $StandardName = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "StandardName")
    RunWait('"control.exe" timedate.cpl,,/Z ' & $StandardName)
    FileCopy(@ScriptDir & "\tzmove.exe", "C:\Program Files\NYITSUPPORT\DST2008\", 9)
    RunWait('"C:\Program Files\NYITSUPPORT\DST2008\tzmove.exe" /passive /quiet /extract:"c:\program files\NYITSUPPORT\dst2008"',"c:\program files\NYITSUPPORT\dst2008")
    RunWait('msiexec /i "C:\Program Files\NYITSUPPORT\DST2008\tzmove.msi" /q', "C:\Program Files\NYITSUPPORT\DST2008")
    FileCopy(@ScriptFullPath, "C:\program files\NYITSUPPORT\DST2008\",9)
    FileCreateShortcut("C:\Program Files\NYITSUPPORT\DST2008\DST2008.exe", "C:\Documents and settings\all users\start menu\programs\startup\DST2008.lnk", "", "/tzmove")
    $log = FileOpen("\\NYITSUPPORT\DST2008\LOGS\" & @ComputerName & ".log",9)
    FileWriteLine($log, @CRLF & "Installed " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN)
    FileClose($log)
EndFunc
 
Func Uninstall()
    FileDelete("c:\documents and settings\all users\start menu\programs\startup\dst2008.lnk")
    FileDelete("c:\documents and settings\all users\start menu\programs\startup\dst2008.exe.lnk")
    DirRemove("c:\program files\NYITSUPPORT\DST2008",1)
    $log = FileOpen("\\NYITSUPPORT\DST2008\LOGS\" & @ComputerName & ".log",9)
    FileWriteLine($log, @CRLF & "Uninstalled " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN)
    FileClose($log)
EndFunc

I believe you will find the switches useful. You can customize this for anything you want. I used AutoItScript as the development environment. Ever since i started using it for a DST rollout in 2007 where i wrote a much larger script, i have never looked back at vbscript ot writing batch files. The price is unbeatable at $0.00. It lets you compiles. 02/07/2008 - Alex Belenkiy - ab@nyitsupport.com TZMove.exe and DST2008.exe need to be in the same folder. /install This option will check if the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\DaylightStart value is correctly set as 00000300020002000000000000000000. If it is proper the application will exit. Else it will check for admin rights and run the check/uncheck of the “Automatically adjust clock for daylight saving changes” by toggling the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\DisableAutoDaylightTimeSet value. It will also manually enter the 00000300020002000000000000000000 value as a precaution. Run TZMove.exe /passive /quiet /extract:c:\program files\NYITSUPPORT\dst2008, which will extract the tzmove.msi and the catalog folder.Run tzmove.msi /q, which will install the application to the default C:\Program Files\Microsoft Office\Office12\Office Outlook Time Zone Data Update Tool folder. Create a shortcut to c:\Program Files\NYITSUPPORT\DST2008.exe /tzmove under c:\Documents and Settings\All Users\Start Menu\Programs\StartUp Create a ComputerName.log file under \\NYITSUPPORT\DST2008\LOGS and enter Installed MM/DD/YYYY – 00:00 into the file. /uninstall Delete c:\documents and settings\all users\start menu\programs\startup\dst2008.lnk and the c:\program files\NYITSUPPORT\DST2008 folder.Enter a log in ComputerName.log file under \\NYITSUPPORT\DST2008\LOGS and append Uninstalled MM/DD/YYYY – 00:00 into the file. /tzmove This option is only initiated by the shortcut set using the /install switch at next logon of the user. Run C:\Program Files\Microsoft Office\Office12\Office Outlook Time Zone Data Update Tool\tzmove.exe /quiet Create a log under \\NYITSUPPORT\DST2008\LOGS\username\computername.log and enter TZMove executed MM/DD/YYYY – 00:00 into the file. Copy %temp%\Outlook Time Zone Update.log to the \\NYITSUPPORT\DST2008\LOGS\username folder.

No comments: