Skip to content

Commit 82f3403

Browse files
committed
Detect HW make/model
1 parent 931614d commit 82f3403

File tree

6 files changed

+654
-0
lines changed

6 files changed

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

0 commit comments

Comments
 (0)