Skip to content

Commit f873055

Browse files
committed
BIOS release date as native timedate object
1 parent cd333cb commit f873055

File tree

2 files changed

+231
-0
lines changed

2 files changed

+231
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
Function GetBIOSReleaseDateAsNativeDatetimeObject(ByRef datetimeReleaseDate)
2+
'region FunctionMetadata ####################################################
3+
' This function obtains the computer's systems management BIOS release date as a local time
4+
' zone-adjusted VBScript-native datetime object (i.e., VT_DATE object), if available and
5+
' configured by the computer's manufacturer.
6+
'
7+
' The function takes one positional argument (datetimeReleaseDate), which is populated upon
8+
' success with a VBScript-native datetime object (i.e., a VT_DATE object) containing the
9+
' computer's systems management BIOS release date. The date and time are adjusted to this
10+
' computer's local time zone. The systems management BIOS release date is equivalent to the
11+
' Win32_BIOS object property ReleaseDate, but converted from CIM_TIMEDATE to VT_DATE
12+
'
13+
' The function returns a 0 if the systems management BIOS release date was obtained
14+
' successfully as a VBScript-native datetime (i.e., VT_DATE) object. It returns a negative
15+
' integer if an error occurred retrieving it. Finally, it returns a positive integer if the
16+
' systems management BIOS release date was obtained, but multiple BIOS instances were
17+
' present that contained data for the systems management BIOS release date string. When
18+
' this happens, only the first Win32_BIOS instance containing data for the systems
19+
' management BIOS release date string is used.
20+
'
21+
' Example:
22+
' intReturnCode = GetBIOSReleaseDateAsNativeDatetimeObject(datetimeReleaseDate)
23+
' If intReturnCode >= 0 Then
24+
' ' The systems management BIOS release date was retrieved successfully in VBScript-
25+
' ' native VT_DATE format and is stored indatetimeReleaseDate
26+
' End If
27+
'
28+
' Version: 1.0.20210711.0
29+
'endregion FunctionMetadata ####################################################
30+
31+
'region License ####################################################
32+
' Copyright 2021 Frank Lesniak
33+
'
34+
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
35+
' software and associated documentation files (the "Software"), to deal in the Software
36+
' without restriction, including without limitation the rights to use, copy, modify, merge,
37+
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
38+
' persons to whom the Software is furnished to do so, subject to the following conditions:
39+
'
40+
' The above copyright notice and this permission notice shall be included in all copies or
41+
' substantial portions of the Software.
42+
'
43+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
44+
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
45+
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
46+
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
47+
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
48+
' DEALINGS IN THE SOFTWARE.
49+
'endregion License ####################################################
50+
51+
'region DownloadLocationNotice ####################################################
52+
' The most up-to-date version of this script can be found on the author's GitHub repository
53+
' at https://github.com/franklesniak/sysadmin-accelerator
54+
'endregion DownloadLocationNotice ####################################################
55+
56+
'region Acknowledgements ####################################################
57+
' None!
58+
'endregion Acknowledgements ####################################################
59+
60+
'region DependsOn ####################################################
61+
' ConnectLocalWMINamespace()
62+
' GetBIOSInstancesUsingWMINamespace()
63+
' GetComputerSystemInstancesUsingWMINamespace()
64+
' GetTimeZoneInstancesUsingWMINamespace()
65+
' GetBIOSReleaseDateAsNativeDatetimeObjectUsingBIOSComputerSystemAndTimeZoneInstances()
66+
'endregion DependsOn ####################################################
67+
68+
Dim intFunctionReturn
69+
Dim intReturnMultiplier
70+
Dim intReturnCode
71+
72+
Dim datetimeResultToReturn
73+
Dim strBIOSReleaseDate
74+
Dim objSWbemServicesWMINamespace
75+
Dim arrBIOSInstances
76+
Dim arrComputerSystemInstances
77+
Dim arrTimeZoneInstances
78+
79+
Err.Clear
80+
81+
intFunctionReturn = 0
82+
intReturnMultiplier = 1
83+
datetimeResultToReturn = Null
84+
85+
intFunctionReturn = ConnectLocalWMINamespace(objSWbemServicesWMINamespace, Null, Null)
86+
If intFunctionReturn = 0 Then
87+
' Successfully connected to the local computer's root\CIMv2 WMI Namespace
88+
intFunctionReturn = GetBIOSInstancesUsingWMINamespace(arrBIOSInstances, objSWbemServicesWMINamespace)
89+
If intFunctionReturn >= 0 Then
90+
' At least one Win32_BIOS instance was retrieved successfully
91+
intReturnCode = GetComputerSystemInstancesUsingWMINamespace(arrComputerSystemInstances, objSWbemServicesWMINamespace)
92+
intReturnCode = GetTimeZoneInstancesUsingWMINamespace(arrTimeZoneInstances, objSWbemServicesWMINamespace)
93+
intReturnCode = GetBIOSReleaseDateAsNativeDatetimeObjectUsingBIOSComputerSystemAndTimeZoneInstances(datetimeResultToReturn, arrBIOSInstances, arrComputerSystemInstances, arrTimeZoneInstances)
94+
If intReturnCode >= 0 Then
95+
' Success!
96+
Else
97+
intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier)
98+
End If
99+
End If
100+
End If
101+
102+
If intFunctionReturn >= 0 Then
103+
datetimeReleaseDate = datetimeResultToReturn
104+
End If
105+
106+
GetBIOSReleaseDateAsNativeDatetimeObject = intFunctionReturn
107+
End Function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
Function GetBIOSReleaseDateAsNativeDatetimeObjectUsingBIOSComputerSystemAndTimeZoneInstances(ByRef datetimeReleaseDate, ByVal arrBIOSInstances, ByVal arrComputerSystemInstances, ByVal arrTimeZoneInstances)
2+
'region FunctionMetadata ####################################################
3+
' Assuming that arrBIOSInstances represents an array / collection of the available BIOS
4+
' instances (of type Win32_BIOS), that arrComputerSystemInstances represents an array /
5+
' collection of the available computer system instances (of type Win32_ComputerSystem), and
6+
' arrTimeZoneInstances represents an array / collection of the available time zone
7+
' instances (of type Win32_TimeZone), this function obtains the computer's systems
8+
' management BIOS release date as a local time zone-adjusted VBScript-native datetime
9+
' object (i.e., VT_DATE object), if available and configured by the computer's
10+
' manufacturer.
11+
'
12+
' The function takes four positional arguments:
13+
' - The first argument (datetimeReleaseDate) is populated upon success with a VBScript-
14+
' native datetime object (i.e., a VT_DATE object) containing the computer's systems
15+
' management BIOS release date. The date and time are adjusted to this computer's local
16+
' time zone. The systems management BIOS release date is equivalent to the Win32_BIOS
17+
' object property ReleaseDate, but converted from CIM_TIMEDATE to VT_DATE
18+
' - The second argument (arrBIOSInstances) is an array/collection of objects of class
19+
' Win32_BIOS
20+
' - The third argument (arrComputerSystemInstances) is an array/collection of objects of
21+
' class Win32_ComputerSystem
22+
' - The fourth argument (arrTimeZoneInstances) is an array/collection of objects of class
23+
' Win32_TimeZone
24+
'
25+
' The function returns a 0 if the systems management BIOS release date was obtained
26+
' successfully as a VBScript-native datetime (i.e., VT_DATE) object. It returns a negative
27+
' integer if an error occurred retrieving it. Finally, it returns a positive integer if the
28+
' systems management BIOS release date was obtained, but multiple BIOS instances were
29+
' present that contained data for the systems management BIOS release date string. When
30+
' this happens, only the first Win32_BIOS instance containing data for the systems
31+
' management BIOS release date string is used.
32+
'
33+
' Example:
34+
' intReturnCode = ConnectLocalWMINamespace(objSWbemServicesWMINamespace, Null, Null)
35+
' If intReturnCode = 0 Then
36+
' ' Successfully connected to the local computer's root\CIMv2 WMI Namespace
37+
' intReturnCode = GetBIOSInstancesUsingWMINamespace(arrBIOSInstances, objSWbemServicesWMINamespace)
38+
' If intReturnCode >= 0 Then
39+
' ' At least one Win32_BIOS instance was retrieved successfully
40+
' intReturnCode = GetComputerSystemInstancesUsingWMINamespace(arrComputerSystemInstances, objSWbemServicesWMINamespace)
41+
' If intReturnCode >= 0 Then
42+
' ' At least one Win32_ComputerSystem instance was retrieved successfully
43+
' intReturnCode = GetTimeZoneInstancesUsingWMINamespace(arrTimeZoneInstances, objSWbemServicesWMINamespace)
44+
' If intReturnCode >= 0 Then
45+
' ' At least one Win32_TimeZone instance was retrieved successfully
46+
' intReturnCode = GetBIOSReleaseDateAsNativeDatetimeObjectUsingBIOSComputerSystemAndTimeZoneInstances(datetimeReleaseDate, arrBIOSInstances, arrComputerSystemInstances, arrTimeZoneInstances)
47+
' If intReturnCode >= 0 Then
48+
' ' The systems management BIOS release date was retrieved
49+
' ' successfully in VBScript-native VT_DATE format and is stored in
50+
' ' datetimeReleaseDate
51+
' End If
52+
' End If
53+
' End If
54+
' End If
55+
' End If
56+
'
57+
' Version: 1.0.20210711.0
58+
'endregion FunctionMetadata ####################################################
59+
60+
'region License ####################################################
61+
' Copyright 2021 Frank Lesniak
62+
'
63+
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
64+
' software and associated documentation files (the "Software"), to deal in the Software
65+
' without restriction, including without limitation the rights to use, copy, modify, merge,
66+
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
67+
' persons to whom the Software is furnished to do so, subject to the following conditions:
68+
'
69+
' The above copyright notice and this permission notice shall be included in all copies or
70+
' substantial portions of the Software.
71+
'
72+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
73+
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
74+
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
75+
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
76+
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
77+
' DEALINGS IN THE SOFTWARE.
78+
'endregion License ####################################################
79+
80+
'region DownloadLocationNotice ####################################################
81+
' The most up-to-date version of this script can be found on the author's GitHub repository
82+
' at https://github.com/franklesniak/sysadmin-accelerator
83+
'endregion DownloadLocationNotice ####################################################
84+
85+
'region Acknowledgements ####################################################
86+
' None!
87+
'endregion Acknowledgements ####################################################
88+
89+
'region DependsOn ####################################################
90+
' GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances()
91+
' ConvertStringCIMDATETIMEToVTDATELocalTimeUsingComputerSystemAndTimeZoneInstances()
92+
'endregion DependsOn ####################################################
93+
94+
Dim intFunctionReturn
95+
Dim intReturnMultiplier
96+
Dim intReturnCode
97+
98+
Dim datetimeResultToReturn
99+
Dim strBIOSReleaseDate
100+
101+
Err.Clear
102+
103+
intFunctionReturn = 0
104+
intReturnMultiplier = 128 * 8
105+
datetimeResultToReturn = Null
106+
107+
intFunctionReturn = GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances(strBIOSReleaseDate, arrBIOSInstances)
108+
If intFunctionReturn >= 0 Then
109+
' One or more Win32_BIOS instances had a valid release date
110+
intReturnCode = ConvertStringCIMDATETIMEToVTDATELocalTimeUsingComputerSystemAndTimeZoneInstances(datetimeResultToReturn, strBIOSReleaseDate, arrComputerSystemInstances, arrTimeZoneInstances)
111+
If intReturnCode >= 0 Then
112+
' Conversion completed successfully
113+
Else
114+
' Conversion failed
115+
intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier)
116+
End If
117+
End If
118+
119+
If intFunctionReturn >= 0 Then
120+
datetimeReleaseDate = datetimeResultToReturn
121+
End If
122+
123+
GetBIOSReleaseDateAsNativeDatetimeObjectUsingBIOSComputerSystemAndTimeZoneInstances = intFunctionReturn
124+
End Function

0 commit comments

Comments
 (0)