|
| 1 | +Function GetBIOSInstancesUsingWMINamespace(ByRef arrBIOSInstances, ByVal objWMINamespace) |
| 2 | + 'region FunctionMetadata #################################################### |
| 3 | + ' Assuming that objWMINamespace represents a successful connection to the root\CIMv2 |
| 4 | + ' WMI namespace, this function retrieves the Win32_BIOS instances and stores them |
| 5 | + ' in arrBIOSInstances. |
| 6 | + ' |
| 7 | + ' The function takes two positional arguments: |
| 8 | + ' - The first argument (arrBIOSInstances) is populated upon success with the BIOS |
| 9 | + ' instances returned from WMI of type Win32_BIOS |
| 10 | + ' - The second argument (objWMINamespace) is a WMI Namespace connection argument that must |
| 11 | + ' already be connected to the WMI namespace root\CIMv2 |
| 12 | + ' |
| 13 | + ' The function returns 0 if Win32_BIOS instances were retrieved successfully, and there was |
| 14 | + ' one BIOS instance (as expected). If no Win32_BIOS objects could be retrieved, then the |
| 15 | + ' function returns a negative number. If there are unexpectedly multiple instances of |
| 16 | + ' Win32_BIOS, then the function returns a positive number equal to the number of WMI |
| 17 | + ' instances retrieved minus one. |
| 18 | + ' |
| 19 | + ' Example: |
| 20 | + ' intReturnCode = ConnectLocalWMINamespace(objSWbemServicesWMINamespace, Null, Null) |
| 21 | + ' If intReturnCode = 0 Then |
| 22 | + ' ' Successfully connected to the local computer's root\CIMv2 WMI Namespace |
| 23 | + ' intReturnCode = GetBIOSInstancesUsingWMINamespace(arrBIOSInstances, objSWbemServicesWMINamespace) |
| 24 | + ' If intReturnCode = 0 Then |
| 25 | + ' ' The Win32_BIOS instance was retrieved successfully and is available |
| 26 | + ' ' at arrBIOSInstances.ItemIndex(0) |
| 27 | + ' ElseIf intReturnCode > 0 Then |
| 28 | + ' ' More than one Win32_BIOS instance was retrieved, which is |
| 29 | + ' ' unexpected. |
| 30 | + ' Else |
| 31 | + ' ' An error occurred and no Win32_BIOS instances were retrieved |
| 32 | + ' End If |
| 33 | + ' End If |
| 34 | + ' |
| 35 | + ' Version: 1.0.20210624.0 |
| 36 | + 'endregion FunctionMetadata #################################################### |
| 37 | + |
| 38 | + 'region License #################################################### |
| 39 | + ' Copyright 2021 Frank Lesniak |
| 40 | + ' |
| 41 | + ' Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 42 | + ' software and associated documentation files (the "Software"), to deal in the Software |
| 43 | + ' without restriction, including without limitation the rights to use, copy, modify, merge, |
| 44 | + ' publish, distribute, sublicense, and/or sell copies of the Software, and to permit |
| 45 | + ' persons to whom the Software is furnished to do so, subject to the following conditions: |
| 46 | + ' |
| 47 | + ' The above copyright notice and this permission notice shall be included in all copies or |
| 48 | + ' substantial portions of the Software. |
| 49 | + ' |
| 50 | + ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 51 | + ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 52 | + ' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 53 | + ' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 54 | + ' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 55 | + ' DEALINGS IN THE SOFTWARE. |
| 56 | + 'endregion License #################################################### |
| 57 | + |
| 58 | + 'region DownloadLocationNotice #################################################### |
| 59 | + ' The most up-to-date version of this script can be found on the author's GitHub repository |
| 60 | + ' at https://github.com/franklesniak/sysadmin-accelerator |
| 61 | + 'endregion DownloadLocationNotice #################################################### |
| 62 | + |
| 63 | + 'region Acknowledgements #################################################### |
| 64 | + ' None! |
| 65 | + 'endregion Acknowledgements #################################################### |
| 66 | + |
| 67 | + 'region DependsOn #################################################### |
| 68 | + ' TestObjectForData() |
| 69 | + ' TestObjectIsAnyTypeOfInteger() |
| 70 | + 'endregion DependsOn #################################################### |
| 71 | + |
| 72 | + Dim intFunctionReturn |
| 73 | + Dim intReturnMultiplier |
| 74 | + Dim arrWorkingBIOSInstances |
| 75 | + Dim intTemp |
| 76 | + |
| 77 | + Err.Clear |
| 78 | + |
| 79 | + intFunctionReturn = 0 |
| 80 | + intReturnMultiplier = 1 |
| 81 | + |
| 82 | + If TestObjectForData(objWMINamespace) <> True Then |
| 83 | + intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier) |
| 84 | + Else |
| 85 | + On Error Resume Next |
| 86 | + Set arrWorkingBIOSInstances = objWMINamespace.InstancesOf("Win32_BIOS") |
| 87 | + If Err Then |
| 88 | + On Error Goto 0 |
| 89 | + Err.Clear |
| 90 | + intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier) |
| 91 | + Else |
| 92 | + intTemp = arrWorkingBIOSInstances.Count |
| 93 | + If Err Then |
| 94 | + On Error Goto 0 |
| 95 | + Err.Clear |
| 96 | + intFunctionReturn = intFunctionReturn + (-4 * intReturnMultiplier) |
| 97 | + Else |
| 98 | + On Error Goto 0 |
| 99 | + If TestObjectIsAnyTypeOfInteger(intTemp) = False Then |
| 100 | + intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier) |
| 101 | + Else |
| 102 | + If intTemp < 0 Then |
| 103 | + intFunctionReturn = intFunctionReturn + (-6 * intReturnMultiplier) |
| 104 | + Else |
| 105 | + ' intTemp >= 0 |
| 106 | + intFunctionReturn = intTemp - 1 |
| 107 | + ' -1 would be returned if there are no Win32_BIOS instances |
| 108 | + End If |
| 109 | + End If |
| 110 | + End If |
| 111 | + End If |
| 112 | + End If |
| 113 | + |
| 114 | + If intFunctionReturn >= 0 Then |
| 115 | + On Error Resume Next |
| 116 | + Set arrBIOSInstances = objWMINamespace.InstancesOf("Win32_BIOS") |
| 117 | + If Err Then |
| 118 | + On Error Goto 0 |
| 119 | + Err.Clear |
| 120 | + intFunctionReturn = (-7 * intReturnMultiplier) |
| 121 | + Else |
| 122 | + On Error Goto 0 |
| 123 | + End If |
| 124 | + End If |
| 125 | + |
| 126 | + GetBIOSInstancesUsingWMINamespace = intFunctionReturn |
| 127 | +End Function |
0 commit comments