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