WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Set Timezone Code


;===========================================================================
;
; This was written based on specific requirements for someone who was
; was setting up laptops for the Red Cross.
;
; This gets info from the registry based on a predefined list of
; time zones. It then updates the Time Zone Information in the
; registry based on a selection in an itembox in a dialog.
;
; It assumes "standard" time - it does not take into account
; daylight savings time.
;
; Written and tested on Win98. Don't know if other OS's would be
; different.
;
;  NOTE:  I ran this on Win XP and found it didn't work.  I made a change
;         and it should work on NT, 2K, XP but is not completely tested.
;
;===========================================================================


;===========================================================================
;
; Timezone program
;
;===========================================================================

:init

  IntControl(12,5,0,0,0)                           ; Allow quite termination

;  Timedelay(2)
  exepath = FilePath(IntControl(1004,0,0,0,0))

  ; Turn on debugging?
  If IsKeyDown(@CTRL) || FileExist("%exepath%debugon.chk")
    Debug(@ON)
  EndIf

  ; Turn on debug tracing?
  If IsKeyDown(@SHIFT) || FileExist("%exepath%debugtraceon.chk")
    DebugTrace(@ON,"%exepath%trace2.txt")
  EndIf

  spaces = StrFill(" ",50)
  tzsel = "NONE"

  tzinfo = StrCat("(GMT-05:00) Eastern Time (PR/VI)",spaces,"^eastern")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-05:00) Eastern Time (US & Canada)",spaces,"^Eastern Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-06:00) Central Time (US & Canada)",spaces,"^Central Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-07:00) Mountain Time (US & Canada)",spaces,"^Mountain Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-08:00) Pacific Time (US & Canada); Tijuana",spaces,"^Pacific Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-09:00) Alaska",spaces,"^Alaskan Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT-10:00) Hawaii",spaces,"^Hawaiian Standard Time")
  tzinfo = StrCat(tzinfo,@TAB,"(GMT+10:00) Guam, Port Moresby",spaces,"^West Pacific Standard Time")

  GoSub definefuncs


;===========================================================================
:main

TZFormat=`WWWDLGED,6.1`

TZCaption=`Set Time Zone`
TZX=171
TZY=117
TZWidth=142
TZHeight=098
TZNumControls=004
TZProcedure=`TZCBP`
TZFont=`DEFAULT`
TZTextColor=`DEFAULT`
TZBackground=`DEFAULT,DEFAULT`
TZConfig=0

TZ001=`009,077,036,012,PUSHBUTTON,DEFAULT,"Set",1,2,32,DEFAULT,DEFAULT,DEFAULT`
TZ002=`057,077,036,012,PUSHBUTTON,DEFAULT,"Cancel",99,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
TZ003=`009,003,074,008,STATICTEXT,DEFAULT,"Pick Desired Timezone",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
TZ004=`007,015,124,056,ITEMBOX,tzinfo,DEFAULT,DEFAULT,1,256,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("TZ")

If tzsel == "NOT CHANGED"
  displaymsg = tzsel
Else
  newzone = StrTrim(ItemExtract(1,tzsel,"^"))
  displaymsg = "Time Zone set to %newzone%"
EndIf

Display(2,"Time Zone Set",displaymsg)


;===========================================================================
:finish

  Exit


;===========================================================================
:definefuncs

  #DefineSubRoutine TZCBP(TZ_Handle,TZ_Message,TZ_ID,rsvd1,rsvd2)

    ;DialogprocOptions Constants
    MSG_INIT=0                ; The one-time initilization
    MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
    MSG_ITEMBOXDOUBLECLICK=13  ; Get double-click message on an ItemBox

    ;DialogControlSet / DialogControlGet Constants
    DC_ITEMBOXCONTENTS=5      ; ITEMBOX FILELISTBOX DROPLISTBOX
    DC_ITEMBOXSELECT=6        ; ITEMBOX FILELISTBOX DROPLISTBOX

    Switch TZ_Message

      Case MSG_INIT
        DialogProcOptions(TZ_Handle,MSG_BUTTONPUSHED,@TRUE)
        DialogProcOptions(TZ_Handle,MSG_ITEMBOXDOUBLECLICK,@TRUE)
        Return(-1)

      Case MSG_ITEMBOXDOUBLECLICK
        tzsel = DialogControlGet(TZ_Handle,004,DC_ITEMBOXSELECT)
        keyname = ItemExtract(2,tzsel,"^")
        updatetimezone(keyname)
        Return(1)

      Case MSG_BUTTONPUSHED
        Switch TZ_ID
          Case 001
            tzsel = DialogControlGet(TZ_Handle,004,DC_ITEMBOXSELECT)
            keyname = ItemExtract(2,tzsel,"^")
            updatetimezone(keyname)
            Return(-1)

          Case 002
            tzsel = "NOT CHANGED"
            Return(-1)

        EndSwitch           ;TZ_ID
        Return(-1)          ;  Do default processing

    EndSwitch       ; TZ_Message
    Return(-1)      ;  Do default processing

  #EndSubRoutine       ;End of Dialog Callback TZCBP


  #DefineFunction updatetimezone(keyname)

    keytoget = StrCat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\",keyname)
    hnd = RegOpenKey(@REGMACHINE,keytoget)
    type1 = RegEntryType(hnd,"[dlt]")
    dltname = RegQueryEx(hnd,"[dlt]","",type1)
    stdname = RegQueryEx(hnd,"[std]","",type1)
    type2 = RegEntryType(hnd,"[tzi]")
    tzi = RegQueryEx(hnd,"[tzi]","",type2)
    bias = StrSub(tzi,1,11)
    stdbias = StrSub(tzi,13,11)
    dltbias = StrSub(tzi,25,11)
    stdstart = StrSub(tzi,37,47)
    dltstart = StrSub(tzi,85,47)
    If dltstart == "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
      dltflag = "00 00 00 00"
    Else
      dltflag = "01 00 00 00"
    EndIf

    RegCloseKey(hnd)

    ; Ok, now we have all the info. Update the Time Zone Info

    keytoupdate = StrCat("System\CurrentControlSet\Control\TimeZoneInformation")
    hnd = RegOpenKey(@REGMACHINE,keytoupdate)
    stat = RegSetValue(hnd,"[daylightname]",dltname)
    stat = RegSetValue(hnd,"[standardname]",stdname)
    stat = RegSetBin(hnd,"[activetimebias]",bias)
    stat = RegSetBin(hnd,"[bias]",bias)
    stat = RegSetBin(hnd,"[daylightbias]",dltbias)
    stat = RegSetBin(hnd,"[standardbias]",stdbias)
    stat = RegSetBin(hnd,"[daylightflag]",dltflag)
    stat = RegSetBin(hnd,"[daylightstart]",dltstart)
    stat = RegSetBin(hnd,"[standardstart]",stdstart)

    RegCloseKey(hnd)

    Return(@TRUE)

  #EndFunction

  Return

  Exit


Article ID:   W16704
File Created: 2005:02:18:12:21:54
Last Updated: 2005:02:18:12:21:54