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

WMI
plus
plus

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

Get Daylight Savings Time

Keywords:    Get Daylight Savings Time


;***************************************************************************
;** WMI_Initalize()
;** Initializes WMI session.
;** 
;** Parameters: 
;** None.
;** 
;** Returns: 
;** an array of object handles, that should ultimately be 
;** passed to WMI_Close()
;** 
;** Note: The object handle referenced at the array subscript 0
;** ObjArray[0] is the Service object handle (objService) that
;** that is required by the other WMI functions. 
;**
;***************************************************************************
#DefineFunction WMI_Initalize()
objLocator = ObjectOpen("WbemScripting.SWbemLocator")
objService = objLocator.ConnectServer()
objSecurity = objService.Security_
objSecurity.ImpersonationLevel = 3
;Fill array with Object handles
ObjArray=ArrDimension(3)
ObjArray[0] = objService
ObjArray[1] = objLocator
ObjArray[2] = objSecurity
Return ObjArray
#EndFunction

;***************************************************************************
;** WMI_Close(ObjectArray)
;** Closes all object handles initialized by WMI_Initalize.
;** 
;** Parameters: 
;** ObjectArray Array returned by WMI_Initalize.
;** 
;** Returns: 
;** Always 1. 
;** 
;***************************************************************************
#DefineFunction WMI_Close(ObjectArray)
count = ArrInfo (ObjectArray,6)
For x = 0 to count-1
ObjectClose(ObjectArray[x]) ;i.e., objSecurity,objLocator,objService
Next
return 1
#EndFunction

;***************************************************************************
;** WMI_Get_Property(objService,Classname,Property,Instance)
;** 
;** 
;** Parameters: 
;** objService The object handle referenced at the array subscript 0
;** ObjArray[0] is the Service object handle (objService) that
;** that is required by the other WMI functions. .
;** 
;** Classname a WMI object class. i.e. Win32_Process
;** 
;** 
;** Property a property of the class object. 
;** 
;** 
;** Instance an integer the specifies the instance of the class object.
;** 
;** 
;** Returns: 
;** Value of the property
;** 
;***************************************************************************
#DefineFunction WMI_Get_Property(objService,Classname,Property,Instance)
Value=""
Str = ""
InstanceFound = 0
WMIObj = objService.InstancesOf(Classname)
hEnum = ObjectCollectionOpen(WMIObj)
InstanceCnt = 0
While 1
Obj = ObjectCollectionNext(hEnum)
If Obj == 0 then Break
If InstanceCnt == Instance
InstanceFound = 1
Value = Obj.%Property%
Str = StrCat(Str,@tab,Value)
Endif
InstanceCnt = InstanceCnt+1
EndWhile
Str = StrTrim(Str)
ObjectCollectionClose(hEnum)
ObjectClose(WMIObj)
if InstanceFound == 1
Return Str
Else
Message("WMI_Get_Property Error","Instance specified was not found")
Return 0
Endif
#EndFunction

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; How to grab date Daylight savings occurs on
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objArr = WMI_Initalize()
;grab objService object
objSvc = objArr[0]
Daylightsavings = ""
Class = "Win32_TimeZone"
;Proparray = Arrayize("DaylightYear,DaylightMonth,DaylightDay,DaylightHour,DaylightMinute,DaylightSecond",",")
Proparray = Arrayize("DaylightYear,DaylightMonth,DaylightDayOfWeek,DaylightDay,DaylightHour,DaylightMinute,DaylightSecond",",")
Valuearray=ArrDimension(ArrInfo (Proparray, 6))
Instance = 0 
count = ArrInfo(Proparray,6)
For x = 0 to Count-1
		prop = Proparray[x]
		
		Valuearray[x] = WMI_Get_Property(objSvc, Class,Prop,Instance)
		if Strlen(Valuearray[x])<2 then Valuearray[x]=StrCat(0,Valuearray[x])
			if prop=="DaylightYear" 
				if Strlen(Valuearray[x])<4
				Valuearray[x] = "0000"
			Endif
		endif
		if x == 0
		Daylightsavings = Valuearray[x]
		else
		Daylightsavings = StrCat(Daylightsavings,":",Valuearray[x])
		endif
Next
;Display results
;Message("Daylight savings occurs on",Daylightsavings)
select valuearray[3]
		case 1
		d="1st"
		break
		case 2
		d="2nd"
		break
		case 3
		d="3rd"
		break
		case 4
		d="4th"
		break
		case 5
		d="last"
		break
		case valuearray[3]
		d="?st"
endselect
dname=itemextract(valuearray[3]+1,"Sunday-Monday-Tueday-Wednesday-Thursday-Friday-Saturday","-")
m=itemextract(valuearray[1],"January-February-March-April-May-June-July-August-September-October-November-December","-")
daylightsavings=strcat("Daylight savings time begins on",@crlf,"the ",d," ",dname," in ",m," at ",valuearray[4],":",valuearray[5],":",valuearray[6])

Proparray = Arrayize("StandardYear,StandardMonth,StandardDayOfWeek,StandardDay,StandardHour,StandardMinute,StandardSecond",",")
Valuearray=ArrDimension(ArrInfo (Proparray, 6))
Instance = 0 
count = ArrInfo(Proparray,6)
For x = 0 to Count-1
		prop = Proparray[x]
		
		Valuearray[x] = WMI_Get_Property(objSvc, Class,Prop,Instance)
		if Strlen(Valuearray[x])<2 then Valuearray[x]=StrCat(0,Valuearray[x])
Next
select valuearray[3]
		case 1
		d="1st"
		break
		case 2
		d="2nd"
		break
		case 3
		d="3rd"
		break
		case 4
		d="4th"
		break
		case 5
		d="last"
		break
		case valuearray[3]
		d="?st"
endselect
dname=itemextract(valuearray[3]+1,"Sunday-Monday-Tueday-Wednesday-Thursday-Friday-Saturday","-")
m=itemextract(valuearray[1],"January-February-March-April-May-June-July-August-September-October-November-December","-")
stdtime=strcat("Daylight savings time ends on",@crlf,"the ",d," ",dname," in ",m," at ",valuearray[4],":",valuearray[5],":",valuearray[6])

Message("Daylight savings",strcat(Daylightsavings,@crlf,@crlf,stdtime))
WMI_Close(objArr)
;Free up arrays
Drop(objArr)
return





Article ID:   W15359
File Created: 2002:11:13:12:47:14
Last Updated: 2002:11:13:12:47:14