Skip to content

Commit 2706504

Browse files
committed
Obtain CIM_DATETIME formatted BIOS release date
1 parent 78e51a2 commit 2706504

File tree

2 files changed

+270
-0
lines changed

2 files changed

+270
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Function GetBIOSReleaseDateCIMDATETIMEString(ByRef strBIOSReleaseDate)
2+
'region FunctionMetadata ####################################################
3+
' This function obtains the computer's systems management BIOS release date in DMTF
4+
' CIM_DATETIME string format, if available and configured by the computer's manufacturer.
5+
'
6+
' A CIM_DATETIME object is a string in the following format:
7+
' yyyymmddHHMMSS.mmmmmmsUUU
8+
' yyyy = Four-digit year (0000 through 9999)
9+
' mm = Two-digit month (01 through 12)
10+
' dd = Two-digit day of the month (01 through 31). This value must be appropriate for the
11+
' month. For example, February 31 is invalid
12+
' HH = Two-digit hour of the day using the 24-hour clock (00 through 23)
13+
' MM = Two-digit minute in the hour (00 through 59)
14+
' SS = Two-digit number of seconds in the minute (00 through 59)
15+
' mmmmmm = Six-digit number of microseconds in the second (000000 through 999999). This
16+
' field must always be present to preserve the fixed-length nature of the string
17+
' s = Plus sign (+) or minus sign (-) to indicate a positive or negative offset from
18+
' Universal Time Coordinates (UTC)
19+
' UUU = Three-digit offset indicating the number of minutes that the originating time zone
20+
' deviates from UTC
21+
'
22+
' The function takes one positional argument (strBIOSReleaseDate), which is populated upon
23+
' success with a string in CIM_DATETIME format (see above) containing the computer's
24+
' systems management BIOS release date. The systems management BIOS release date is
25+
' equivalent to the Win32_BIOS object property ReleaseDate
26+
'
27+
' The function returns a 0 if the systems management BIOS release date string was obtained
28+
' successfully. It returns a negative integer if an error occurred retrieving it. Finally,
29+
' it returns a positive integer if the systems management BIOS release date string was
30+
' obtained, but multiple BIOS instances were present that contained data for the systems
31+
' management BIOS release date string. When this happens, only the first Win32_BIOS
32+
' instance containing data for the systems management BIOS release date string is used.
33+
'
34+
' Example:
35+
' intReturnCode = GetBIOSReleaseDateCIMDATETIMEString(strBIOSReleaseDate)
36+
' If intReturnCode >= 0 Then
37+
' ' The systems management BIOS release date string was retrieved successfully and is
38+
' ' stored in strBIOSReleaseDate
39+
' End If
40+
'
41+
' Version: 1.0.20210711.0
42+
'endregion FunctionMetadata ####################################################
43+
44+
'region License ####################################################
45+
' Copyright 2021 Frank Lesniak
46+
'
47+
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
48+
' software and associated documentation files (the "Software"), to deal in the Software
49+
' without restriction, including without limitation the rights to use, copy, modify, merge,
50+
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
51+
' persons to whom the Software is furnished to do so, subject to the following conditions:
52+
'
53+
' The above copyright notice and this permission notice shall be included in all copies or
54+
' substantial portions of the Software.
55+
'
56+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
57+
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
58+
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
59+
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
60+
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
61+
' DEALINGS IN THE SOFTWARE.
62+
'endregion License ####################################################
63+
64+
'region DownloadLocationNotice ####################################################
65+
' The most up-to-date version of this script can be found on the author's GitHub repository
66+
' at https://github.com/franklesniak/sysadmin-accelerator
67+
'endregion DownloadLocationNotice ####################################################
68+
69+
'region Acknowledgements ####################################################
70+
' None!
71+
'endregion Acknowledgements ####################################################
72+
73+
'region DependsOn ####################################################
74+
' GetBIOSInstances()
75+
' GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances()
76+
'endregion DependsOn ####################################################
77+
78+
Dim intFunctionReturn
79+
Dim arrBIOSInstances
80+
Dim strResult
81+
82+
intFunctionReturn = 0
83+
84+
intFunctionReturn = GetBIOSInstances(arrBIOSInstances)
85+
If intFunctionReturn >= 0 Then
86+
' At least one Win32_BIOS instance was retrieved successfully
87+
intFunctionReturn = GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances(strResult, arrBIOSInstances)
88+
If intFunctionReturn >= 0 Then
89+
' The computer's BIOS release date was retrieved successfully and is stored in
90+
' strResult
91+
strBIOSReleaseDate = strResult
92+
End If
93+
End If
94+
95+
GetBIOSReleaseDateCIMDATETIMEString = intFunctionReturn
96+
End Function
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
Function GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances(ByRef strBIOSReleaseDate, ByVal arrBIOSInstances)
2+
'region FunctionMetadata ####################################################
3+
' Assuming that arrBIOSInstances represents an array / collection of the available BIOS
4+
' instances (of type Win32_BIOS), this function obtains the computer's systems management
5+
' BIOS release date in DMTF CIM_DATETIME string format, if available and configured by the
6+
' computer's manufacturer.
7+
'
8+
' A CIM_DATETIME object is a string in the following format:
9+
' yyyymmddHHMMSS.mmmmmmsUUU
10+
' yyyy = Four-digit year (0000 through 9999)
11+
' mm = Two-digit month (01 through 12)
12+
' dd = Two-digit day of the month (01 through 31). This value must be appropriate for the
13+
' month. For example, February 31 is invalid
14+
' HH = Two-digit hour of the day using the 24-hour clock (00 through 23)
15+
' MM = Two-digit minute in the hour (00 through 59)
16+
' SS = Two-digit number of seconds in the minute (00 through 59)
17+
' mmmmmm = Six-digit number of microseconds in the second (000000 through 999999). This
18+
' field must always be present to preserve the fixed-length nature of the string
19+
' s = Plus sign (+) or minus sign (-) to indicate a positive or negative offset from
20+
' Universal Time Coordinates (UTC)
21+
' UUU = Three-digit offset indicating the number of minutes that the originating time zone
22+
' deviates from UTC
23+
'
24+
' The function takes two positional arguments:
25+
' - The first argument (strBIOSReleaseDate) is populated upon success with a string
26+
' in CIM_DATETIME format (see above) containing the computer's systems management BIOS
27+
' release date. The systems management BIOS release date is equivalent to the Win32_BIOS
28+
' object property ReleaseDate
29+
' - The second argument (arrBIOSInstances) is an array/collection of objects of class
30+
' Win32_BIOS
31+
'
32+
' The function returns a 0 if the systems management BIOS release date string was obtained
33+
' successfully. It returns a negative integer if an error occurred retrieving it. Finally,
34+
' it returns a positive integer if the systems management BIOS release date string was
35+
' obtained, but multiple BIOS instances were present that contained data for the systems
36+
' management BIOS release date string. When this happens, only the first Win32_BIOS
37+
' instance containing data for the systems management BIOS release date string is used.
38+
'
39+
' Example:
40+
' intReturnCode = GetBIOSInstances(arrBIOSInstances)
41+
' If intReturnCode >= 0 Then
42+
' ' At least one Win32_BIOS instance was retrieved successfully
43+
' intReturnCode = GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances(strBIOSReleaseDate, arrBIOSInstances)
44+
' If intReturnCode >= 0 Then
45+
' ' The systems management BIOS release date string was retrieved successfully
46+
' ' and is stored in strBIOSReleaseDate
47+
' End If
48+
' End If
49+
'
50+
' Version: 1.0.20210711.0
51+
'endregion FunctionMetadata ####################################################
52+
53+
'region License ####################################################
54+
' Copyright 2021 Frank Lesniak
55+
'
56+
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
57+
' software and associated documentation files (the "Software"), to deal in the Software
58+
' without restriction, including without limitation the rights to use, copy, modify, merge,
59+
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
60+
' persons to whom the Software is furnished to do so, subject to the following conditions:
61+
'
62+
' The above copyright notice and this permission notice shall be included in all copies or
63+
' substantial portions of the Software.
64+
'
65+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
66+
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
67+
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
68+
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
69+
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
70+
' DEALINGS IN THE SOFTWARE.
71+
'endregion License ####################################################
72+
73+
'region DownloadLocationNotice ####################################################
74+
' The most up-to-date version of this script can be found on the author's GitHub repository
75+
' at https://github.com/franklesniak/sysadmin-accelerator
76+
'endregion DownloadLocationNotice ####################################################
77+
78+
'region Acknowledgements ####################################################
79+
' Microsoft, for publishing the document reference for Win32_BIOS:
80+
' https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-bios
81+
'
82+
' Jonathon Reinhart on StackExchange, who help confirm that SMBIOSBIOSVersion is an
83+
' important BIOS attribute to retrieve. The examples are for Linux but helped the author to
84+
' compare a cross-platform example.
85+
'
86+
' The Ubuntu wiki also helped confirm that SMBIOSBIOSVersion is an important attribute,
87+
' even though Ubuntu is a Linux platform - not Windows.
88+
'endregion Acknowledgements ####################################################
89+
90+
'region DependsOn ####################################################
91+
' TestObjectForData()
92+
' TestObjectIsAnyTypeOfInteger()
93+
' TestObjectIsStringContainingData()
94+
'endregion DependsOn ####################################################
95+
96+
Dim intFunctionReturn
97+
Dim intReturnMultiplier
98+
99+
Dim intTemp
100+
Dim intCounterA
101+
Dim strInterimResult
102+
Dim strOldInterimResult
103+
Dim strResultToReturn
104+
Dim intCountOfBIOSes
105+
106+
Err.Clear
107+
108+
intFunctionReturn = 0
109+
intReturnMultiplier = 128
110+
strInterimResult = ""
111+
strResultToReturn = ""
112+
intCountOfBIOSes = 0
113+
114+
If TestObjectForData(arrBIOSInstances) <> True Then
115+
intFunctionReturn = intFunctionReturn + (-1 * intReturnMultiplier)
116+
Else
117+
On Error Resume Next
118+
intTemp = arrBIOSInstances.Count
119+
If Err Then
120+
On Error Goto 0
121+
Err.Clear
122+
intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier)
123+
Else
124+
On Error Goto 0
125+
If TestObjectIsAnyTypeOfInteger(intTemp) = False Then
126+
intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier)
127+
Else
128+
If intTemp < 0 Then
129+
intFunctionReturn = intFunctionReturn + (-4 * intReturnMultiplier)
130+
ElseIf intTemp = 0 Then
131+
intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier)
132+
Else
133+
For intCounterA = 0 To (intTemp - 1)
134+
strOldInterimResult = strInterimResult
135+
On Error Resume Next
136+
strInterimResult = arrBIOSInstances.ItemIndex(intCounterA).ReleaseDate
137+
If Err Then
138+
On Error Goto 0
139+
Err.Clear
140+
strInterimResult = strOldInterimResult
141+
Else
142+
On Error Goto 0
143+
If TestObjectForData(strInterimResult) <> True Then
144+
strInterimResult = strOldInterimResult
145+
Else
146+
' Found a result with real model data
147+
If TestObjectIsStringContainingData(strResultToReturn) = False Then
148+
strResultToReturn = strInterimResult
149+
End If
150+
intCountOfBIOSes = intCountOfBIOSes + 1
151+
End If
152+
End If
153+
Next
154+
End If
155+
End If
156+
End If
157+
End If
158+
159+
If intFunctionReturn >= 0 Then
160+
' No error has occurred yet
161+
If intCountOfBIOSes = 0 Then
162+
' No result found
163+
intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier)
164+
Else
165+
intFunctionReturn = intCountOfBIOSes - 1
166+
End If
167+
End If
168+
169+
If intFunctionReturn >= 0 Then
170+
strBIOSReleaseDate = strResultToReturn
171+
End If
172+
173+
GetBIOSReleaseDateCIMDATETIMEStringUsingBIOSInstances = intFunctionReturn
174+
End Function

0 commit comments

Comments
 (0)