Skip to content

Commit 25b4c2f

Browse files
committed
BIOS manufacturer version string for legacy Microsoft virtualization platform detection
i.e., Hyper-V vs. legacy Virtual Server 2005 versions, Virtual PC, etc.
1 parent f873055 commit 25b4c2f

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Function GetBIOSManufacturerVersionString(ByRef strBIOSManufacturerVersion)
2+
'region FunctionMetadata ####################################################
3+
' This function obtains the computer's BIOS version number in string format as reported by
4+
' the BIOS manufacturer, if available and configured by the computer's manufacturer.
5+
'
6+
' NOTE: The BIOS manufacturer's BIOS version is not usually in .NET version format. For
7+
' example, a Lenovo systems returns a version like "LENOVO - 1510"
8+
'
9+
' NOTE: It is generally preferable to use the Systems Management BIOS version number
10+
' instead of the BIOS manufacturer version number.
11+
'
12+
' The function takes one positional argument (strBIOSManufacturerVersion), which is
13+
' populated upon success with a string containing the computer's systems BIOS version
14+
' number in string format as reported by the BIOS manufacturer. The BIOS manufacturer's
15+
' BIOS version number is equivalent to the Win32_BIOS object property Version
16+
'
17+
' The function returns a 0 if the BIOS version string (as reported by the BIOS
18+
' manufacturer) was obtained successfully. It returns a negative integer if an error
19+
' occurred retrieving it. Finally, it returns a positive integer if the BIOS manufacturer
20+
' BIOS version string was obtained, but multiple BIOS instances were present that contained
21+
' data for the BIOS manufacturer version string. When this happens, only the first
22+
' Win32_BIOS instance containing data for the BIOS version string (as reported by the BIOS
23+
' manufacturer) is used.
24+
'
25+
' Example:
26+
' intReturnCode = GetBIOSManufacturerVersionString(strBIOSManufacturerVersion)
27+
' If intReturnCode >= 0 Then
28+
' ' The BIOS version string as reported by the BIOS manufacturer was retrieved
29+
' ' successfully and is stored in strBIOSManufacturerVersion
30+
' End If
31+
'
32+
' Version: 1.0.20210711.0
33+
'endregion FunctionMetadata ####################################################
34+
35+
'region License ####################################################
36+
' Copyright 2021 Frank Lesniak
37+
'
38+
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
39+
' software and associated documentation files (the "Software"), to deal in the Software
40+
' without restriction, including without limitation the rights to use, copy, modify, merge,
41+
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
42+
' persons to whom the Software is furnished to do so, subject to the following conditions:
43+
'
44+
' The above copyright notice and this permission notice shall be included in all copies or
45+
' substantial portions of the Software.
46+
'
47+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
48+
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
49+
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
50+
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
51+
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
52+
' DEALINGS IN THE SOFTWARE.
53+
'endregion License ####################################################
54+
55+
'region DownloadLocationNotice ####################################################
56+
' The most up-to-date version of this script can be found on the author's GitHub repository
57+
' at https://github.com/franklesniak/sysadmin-accelerator
58+
'endregion DownloadLocationNotice ####################################################
59+
60+
'region Acknowledgements ####################################################
61+
' None!
62+
'endregion Acknowledgements ####################################################
63+
64+
'region DependsOn ####################################################
65+
' GetBIOSInstances()
66+
' GetBIOSManufacturerVersionStringUsingBIOSInstances()
67+
'endregion DependsOn ####################################################
68+
69+
Dim intFunctionReturn
70+
Dim arrBIOSInstances
71+
Dim strResult
72+
73+
intFunctionReturn = 0
74+
75+
intFunctionReturn = GetBIOSInstances(arrBIOSInstances)
76+
If intFunctionReturn >= 0 Then
77+
' At least one Win32_BIOS instance was retrieved successfully
78+
intFunctionReturn = GetBIOSManufacturerVersionStringUsingBIOSInstances(strResult, arrBIOSInstances)
79+
If intFunctionReturn >= 0 Then
80+
' The computer's BIOS version string was retrieved successfully and is stored in
81+
' strResult
82+
strBIOSManufacturerVersion = strResult
83+
End If
84+
End If
85+
86+
GetBIOSManufacturerVersionString = intFunctionReturn
87+
End Function
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Function GetBIOSManufacturerVersionStringUsingBIOSInstances(ByRef strBIOSManufacturerVersion, 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 BIOS version number
5+
' in string format as reported by the BIOS manufacturer, if available and configured by the
6+
' computer's manufacturer.
7+
'
8+
' NOTE: The BIOS manufacturer's BIOS version is not usually in .NET version format. For
9+
' example, a Lenovo systems returns a version like "LENOVO - 1510"
10+
'
11+
' NOTE: It is generally preferable to use the Systems Management BIOS version number
12+
' instead of the BIOS manufacturer version number.
13+
'
14+
' The function takes two positional arguments:
15+
' - The first argument (strBIOSManufacturerVersion) is populated upon success with a
16+
' string containing the computer's systems BIOS version number in string format as
17+
' reported by the BIOS manufacturer. The BIOS manufacturer's BIOS version number is
18+
' equivalent to the Win32_BIOS object property Version
19+
' - The second argument (arrBIOSInstances) is an array/collection of objects of class
20+
' Win32_BIOS
21+
'
22+
' The function returns a 0 if the BIOS version string (as reported by the BIOS
23+
' manufacturer) was obtained successfully. It returns a negative integer if an error
24+
' occurred retrieving it. Finally, it returns a positive integer if the BIOS manufacturer
25+
' BIOS version string was obtained, but multiple BIOS instances were present that contained
26+
' data for the BIOS manufacturer version string. When this happens, only the first
27+
' Win32_BIOS instance containing data for the BIOS version string (as reported by the BIOS
28+
' manufacturer) is used.
29+
'
30+
' Example:
31+
' intReturnCode = GetBIOSInstances(arrBIOSInstances)
32+
' If intReturnCode >= 0 Then
33+
' ' At least one Win32_BIOS instance was retrieved successfully
34+
' intReturnCode = GetBIOSManufacturerVersionStringUsingBIOSInstances(strBIOSManufacturerVersion, arrBIOSInstances)
35+
' If intReturnCode >= 0 Then
36+
' ' The BIOS version string as reported by the BIOS manufacturer was retrieved
37+
' ' successfully and is stored in strBIOSManufacturerVersion
38+
' End If
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+
' Microsoft, for publishing the document reference for Win32_BIOS:
71+
' https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-bios
72+
'endregion Acknowledgements ####################################################
73+
74+
'region DependsOn ####################################################
75+
' TestObjectForData()
76+
' TestObjectIsAnyTypeOfInteger()
77+
'endregion DependsOn ####################################################
78+
79+
Dim intFunctionReturn
80+
Dim intReturnMultiplier
81+
Dim intTemp
82+
Dim intCounterA
83+
Dim strInterimResult
84+
Dim strOldInterimResult
85+
Dim strResultToReturn
86+
Dim intCountOfBIOSes
87+
88+
Err.Clear
89+
90+
intFunctionReturn = 0
91+
intReturnMultiplier = 128
92+
strInterimResult = ""
93+
strResultToReturn = ""
94+
intCountOfBIOSes = 0
95+
96+
If TestObjectForData(arrBIOSInstances) <> True Then
97+
intFunctionReturn = intFunctionReturn + (-1 * intReturnMultiplier)
98+
Else
99+
On Error Resume Next
100+
intTemp = arrBIOSInstances.Count
101+
If Err Then
102+
On Error Goto 0
103+
Err.Clear
104+
intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier)
105+
Else
106+
On Error Goto 0
107+
If TestObjectIsAnyTypeOfInteger(intTemp) = False Then
108+
intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier)
109+
Else
110+
If intTemp < 0 Then
111+
intFunctionReturn = intFunctionReturn + (-4 * intReturnMultiplier)
112+
ElseIf intTemp = 0 Then
113+
intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier)
114+
Else
115+
For intCounterA = 0 To (intTemp - 1)
116+
strOldInterimResult = strInterimResult
117+
On Error Resume Next
118+
strInterimResult = arrBIOSInstances.ItemIndex(intCounterA).Version
119+
If Err Then
120+
On Error Goto 0
121+
Err.Clear
122+
strInterimResult = strOldInterimResult
123+
Else
124+
On Error Goto 0
125+
If TestObjectForData(strInterimResult) <> True Then
126+
strInterimResult = strOldInterimResult
127+
Else
128+
' Found a result with real model data
129+
If TestObjectForData(strResultToReturn) = False Then
130+
strResultToReturn = strInterimResult
131+
End If
132+
intCountOfBIOSes = intCountOfBIOSes + 1
133+
End If
134+
End If
135+
Next
136+
End If
137+
End If
138+
End If
139+
End If
140+
141+
If intFunctionReturn >= 0 Then
142+
' No error has occurred yet
143+
If intCountOfBIOSes = 0 Then
144+
' No result found
145+
intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier)
146+
Else
147+
intFunctionReturn = intCountOfBIOSes - 1
148+
End If
149+
End If
150+
151+
If intFunctionReturn >= 0 Then
152+
strBIOSManufacturerVersion = strResultToReturn
153+
End If
154+
155+
GetBIOSManufacturerVersionStringUsingBIOSInstances = intFunctionReturn
156+
End Function

0 commit comments

Comments
 (0)