Skip to content

Commit d1e6224

Browse files
committed
Detect Parallels, GCP, QEMU/KVM; fix VMware
1 parent c480638 commit d1e6224

File tree

1 file changed

+67
-46
lines changed

1 file changed

+67
-46
lines changed

VBScript/02_Upfront_Encapsulated_Code_With_No_Dependencies/TestComputerIsVirtualMachineUsingManufacturerAndModel.vbs

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
Function TestComputerIsVirtualMachineUsingManufacturerAndModel(ByRef boolIsVM, ByVal strComputerManufacturer, ByVal strComputerModel)
2-
'region FunctionMetadata ####################################################
3-
' Assuming that strComputerManufacturer is a string that is populated with the computer
4-
' manufacturer and strComputerModel is a string that is populated with the computer model
5-
' name or model number, this function determines if the computer is a virtual machine
2+
'region FunctionMetadata #######################################################
3+
' Assuming that strComputerManufacturer is a string that is populated with the
4+
' computer manufacturer and strComputerModel is a string that is populated with the
5+
' computer model name or model number, this function determines if the computer is
6+
' a virtual machine
67
'
78
' The function takes three positional arguments:
8-
' - The first argument (boolIsVM) is populated upon success with a boolean value: True
9-
' when the computer was determined to be a virtual machine, False when the computer was
10-
' determined to not be a virtual machine
11-
' - The second argument (strComputerManufacturer) is a string that must be pre-populated
12-
' with the computer manufacturer
13-
' - The third argument (strComputerModel) is a string that must be pre-populated with the
14-
' computer's model name or model number
9+
' - The first argument (boolIsVM) is populated upon success with a boolean value:
10+
' True when the computer was determined to be a virtual machine, False when the
11+
' computer was determined to not be a virtual machine
12+
' - The second argument (strComputerManufacturer) is a string that must be pre-
13+
' populated with the computer manufacturer
14+
' - The third argument (strComputerModel) is a string that must be pre-populated
15+
' with the computer's model name or model number
1516
'
16-
' The function returns a 0 when the function successfully evaluated whether the computer is
17-
' a virtual machine. The function returns a negative integer if an error occurred.
17+
' The function returns a 0 when the function successfully evaluated whether the
18+
' computer is a virtual machine. The function returns a negative integer if an
19+
' error occurred.
1820
'
1921
' Example:
2022
' intReturnCode = GetComputerSystemInstances(arrComputerSystemInstances)
@@ -26,8 +28,8 @@ Function TestComputerIsVirtualMachineUsingManufacturerAndModel(ByRef boolIsVM, B
2628
' ' strComputerManufacturer
2729
' intReturnCode = GetComputerModelUsingComputerSystemInstances(strComputerModel, arrComputerSystemInstances)
2830
' If intReturnCode >= 0 Then
29-
' ' The computer model name/number was retrieved successfully and is stored
30-
' ' in strComputerModel
31+
' ' The computer model name/number was retrieved successfully and is
32+
' ' stored in strComputerModel
3133
' intReturnCode = TestComputerIsVirtualMachineUsingManufacturerAndModel(boolIsVM, strComputerManufacturer, strComputerModel)
3234
' If intReturnCode = 0 Then
3335
' ' Successfully tested whether this system is a VM
@@ -41,44 +43,53 @@ Function TestComputerIsVirtualMachineUsingManufacturerAndModel(ByRef boolIsVM, B
4143
' End If
4244
' End If
4345
'
44-
' Version: 1.0.20210625.0
45-
'endregion FunctionMetadata ####################################################
46+
' Version: 1.1.20230423.0
47+
'endregion FunctionMetadata #######################################################
4648

47-
'region License ####################################################
48-
' Copyright 2021 Frank Lesniak
49+
'region License ################################################################
50+
' Copyright 2023 Frank Lesniak
4951
'
50-
' Permission is hereby granted, free of charge, to any person obtaining a copy of this
51-
' software and associated documentation files (the "Software"), to deal in the Software
52-
' without restriction, including without limitation the rights to use, copy, modify, merge,
53-
' publish, distribute, sublicense, and/or sell copies of the Software, and to permit
54-
' persons to whom the Software is furnished to do so, subject to the following conditions:
52+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
53+
' this software and associated documentation files (the "Software"), to deal in the
54+
' Software without restriction, including without limitation the rights to use,
55+
' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
56+
' Software, and to permit persons to whom the Software is furnished to do so,
57+
' subject to the following conditions:
5558
'
56-
' The above copyright notice and this permission notice shall be included in all copies or
57-
' substantial portions of the Software.
59+
' The above copyright notice and this permission notice shall be included in all
60+
' copies or substantial portions of the Software.
5861
'
59-
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
60-
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
61-
' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
62-
' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
63-
' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
64-
' DEALINGS IN THE SOFTWARE.
65-
'endregion License ####################################################
62+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63+
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
64+
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
65+
' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
66+
' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
67+
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68+
'endregion License ################################################################
6669

67-
'region DownloadLocationNotice ####################################################
68-
' The most up-to-date version of this script can be found on the author's GitHub repository
69-
' at https://github.com/franklesniak/sysadmin-accelerator
70-
'endregion DownloadLocationNotice ####################################################
70+
'region DownloadLocationNotice #################################################
71+
' The most up-to-date version of this script can be found on the author's GitHub
72+
' repository at https://github.com/franklesniak/sysadmin-accelerator
73+
'endregion DownloadLocationNotice #################################################
7174

72-
'region Acknowledgements ####################################################
73-
' Microsoft, for (intentionally or not) making the Microsoft Deployment Toolkit (MDT) with
74-
' its source code viewable based on it being written in VBS/WSH. MDT has a function that
75-
' determines whether a given system is a desktop/laptop/server/VM, which was useful in
76-
' determining how to approach this function
77-
'endregion Acknowledgements ####################################################
75+
'region Acknowledgements #######################################################
76+
' Microsoft, for (intentionally or not) making the Microsoft Deployment Toolkit
77+
' (MDT) with its source code viewable based on it being written in VBS/WSH. MDT has
78+
' a function that determines whether a given system is a desktop/laptop/server/VM,
79+
' which was useful in determining how to approach this function
80+
'
81+
' Google, for documenting the procedure for detecting whether a virtual machine is
82+
' running on Google Compute Engine:
83+
' https://cloud.google.com/compute/docs/instances/detect-compute-engine#windows-vm_1
84+
'
85+
' Michael Niehaus for comfirming that the model number of a VMware virtual machine
86+
' may show up as "VMware20,1":
87+
' https://oofhours.com/2022/11/25/now-released-vmware-fusion-for-running-windows-on-arm-on-m1-m2-macs/
88+
'endregion Acknowledgements #######################################################
7889

79-
'region DependsOn ####################################################
90+
'region DependsOn ##############################################################
8091
' TestObjectIsStringContainingData()
81-
'endregion DependsOn ####################################################
92+
'endregion DependsOn ##############################################################
8293

8394
Dim intFunctionReturn
8495
Dim intReturnMultiplier
@@ -94,18 +105,28 @@ Function TestComputerIsVirtualMachineUsingManufacturerAndModel(ByRef boolIsVM, B
94105
If strComputerModel = "Virtual Machine" Then
95106
' Microsoft virtual machine
96107
boolInterimResult = True
97-
ElseIf strComputerModel = "VMware Virtual Platform" Or strComputerModel = "VMware7,1" Then
108+
ElseIf strComputerModel = "VMware Virtual Platform" Or strComputerModel = "VMware7,1" Or strComputerModel = "VMware20,1" Then
98109
' VMware virtual machine
99110
boolInterimResult = True
100111
ElseIf strComputerModel = "VirtualBox" Then
101112
' VirtualBox virtual machine
102113
boolInterimResult = True
114+
ElseIf strComputerModel = "Parallels Virtual Platform" Then
115+
' Parallels virtual machine
116+
boolInterimResult = True
117+
ElseIf strComputerModel = "Google Compute Engine" Then
118+
' Google Compute Engine virtual machine
119+
boolInterimResult = True
103120
Else
104121
If TestObjectIsStringContainingData(strComputerManufacturer) <> True Then
105122
intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier)
106123
Else
107124
If strComputerManufacturer = "Xen" Then
108125
' Citrix Xen virtual machine
126+
' Note: could also be running on AWS
127+
boolInterimResult = True
128+
ElseIf strComputerManufacturer = "QEMU" Then
129+
' QEMU / KVM virtual machine
109130
boolInterimResult = True
110131
End If
111132
End If

0 commit comments

Comments
 (0)