|
| 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