Detecting Whether the Installation Is Being Run on a Virtual Machine
InstallShield 2025
InstallShield lets you determine whether an installation is running on any of the following types of virtual machines:
|
•
|
A VMware product such as VMware Player, VMware Workstation, or VMware Server |
To check for virtual machines, you can either use Windows Installer properties, or you can use an InstallScript structure or function.
Note:Bochs Emulator is not detected.
Using Windows Installer Properties to Detect a Virtual Machine
Project:
You can use Windows Installer properties in conditions for items such as features, components, and custom actions in the following project types:
To use Windows Installer properties to detect the presence of a virtual machine and determine the type of virtual machine, you first need to create a custom action that calls the ISDetectVM function in the SetAllUsers.dll file.
To add a custom action that checks for a virtual machine:
|
1.
|
In the View List under Behavior and Logic, click Custom Actions and Sequences (in Basic MSI and InstallScript MSI projects) or Custom Actions (in DIM and Merge Module projects). |
|
2.
|
In the center pane, right-click the Custom Actions explorer, point to New MSI DLL, and click Stored in Binary table. InstallShield adds a new custom action. |
|
3.
|
Change the name of the action to something like ISDetectVM. |
|
4.
|
Configure the custom action’s settings in the right pane: |
|
•
|
In the DLL Filename setting, select the SetAllUsers.dll file. The typical path is: |
<ISRedistPlatformDependentFolder>\SetAllUsers.dll
|
•
|
In the Function Name setting, enter the following name: |
ISDetectVM
|
•
|
In the In-Script Execution setting, select Immediate Execution. |
|
•
|
Schedule the custom action as needed by selecting the appropriate option in one or more sequence settings. |
The custom action sets the following Windows Installer properties at run time:
Windows Installer Properties for Detecting Virtual Machines
|
|
|
|
IS_VM_DETECTED
|
If the value of this property is 1, the installation is running on one of the following virtual machine environments:
|
•
|
A VMware product such as VMware Player, VMware Workstation, or VMware Server |
If the value is not set, no virtual machine has been detected.
|
|
IS_VM_TYPE
|
This property indicates the type of virtual machine that is running the installation. Available values are:
|
•
|
Undefined—No virtual machine has been detected. |
|
•
|
1—The installation is running on a VMware product such as VMware Player, VMware Workstation, or VMware Server. |
|
•
|
2—The installation is running on a Microsoft Hyper-V machine. |
|
•
|
3—The installation is running on a Microsoft Virtual PC machine. |
|
•
|
4—The type of virtual machine is not known. |
|
•
|
5—The installation is running on a Xen machine. |
|
•
|
6—The installation is running on an Amazon EC2 Instance machine. |
|
•
|
8—The installation is running on a QEMU machine. |
|
•
|
9—The installation is running on a Parallels Desktop machine. |
|
•
|
10—The installation is running on a Google Compute machine. |
|
•
|
11—The installation is running on a Microsoft Azure machine. |
|
•
|
12—The installation is running on an EverRun machine. |
|
You can use the aforementioned properties in conditional statements. For example, if your product cannot be used on virtual machines, enter the following conditional statement in the Install Condition setting of the General Information view:
Not IS_VM_DETECTED
If you have a component that should be installed only on VMware images, enter the following conditional statement in the Condition setting of the Components view:
IS_VM_TYPE=1
Using an InstallScript Structure and Variable to Detect a Virtual Machine
Project:You can use an InstallScript structure and variable in event-driven InstallScript code in the following project types:
You can also use the structure and variable in InstallScript custom actions that are in the following project types:
You can use the SYSINFO.bIsVirtualMachine structure in your InstallScript code to determine whether the installation is being run on a virtual machine. In addition, you can use the VIRTUAL_MACHINE_TYPE constant with the GetSystemInfo function to determine which type of virtual machine is present.
For example, in an InstallScript event handler such as OnFirstUIBefore or in an InstallScript custom action, you can use code such as the following snippet:
if (SYSINFO.bIsVirtualMachine) then
SprintfBox (0, "VM", "This is a virtual machine. Type: %d",
GetSystemInfo (VIRTUAL_MACHINE_TYPE, nNumber, szString));
else
MessageBox ("This is not a virtual machine.", 0);
endif;
At run time, a message box is displayed. If the target system is a Microsoft Hyper-V image, a VMware image, a Microsoft Virtual PC image, a Xen image, an Amazon EC2 Instance image, a QEMU image, a Parallels Desktop image, a Google Compute image, a Microsoft Azure image, or an EverRun image, the message box says, “This is a virtual machine,” and it also lists the type of virtual machine. If the target system is not one of those virtual machines, the message box says, “This is not a virtual machine.”
See Also
Building Conditional Statements
SYSINFO
GetSystemInfo