Skip to content

Commit de6d769

Browse files
committed
Lenovo model and others from ComputerSystemProduct
1 parent f24ab37 commit de6d769

8 files changed

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

0 commit comments

Comments
 (0)