Can I detect whether a process is running on a virtual machine using any cloud platform and not on a local machine?

Rohan Pande 335 Reputation points
2023-09-29T06:48:22.02+00:00

Hi,

We have looked into __cpuid. The __cpuid will give us four registers (EAX, EBX, ECX, EDX) values when we pass a function id and an array. Inside ECX 31st bit will let us know hypervisor bit is being set to true or not. That will lead us to know whether we are being running on a virtual machine or a local machine.

Inside this Wikipedia link please check the 31st bit of the table it clearly says it would be zero for physical machines.

I tried a program to know whether that bit value is true or false but, on both machines irrespective of virtual and physical this is set to be true.

#include <stdio.h>
#ifdef _WIN32
#include <intrin.h>
#endif
int isHypervisor(void)
{
#ifdef _WIN32
    int cpuinfo[4];
    __cpuid(cpuinfo, 1);
    if (cpuinfo[2] >> 31 & 1)
        return 1;
#endif
    return 0;
}
int main(int argc, char** argv)
{
    if (isHypervisor())
        printf("Virtual machine: yes\n");
    else
        printf("Virtual machine: no\n");
    return 0;
}

But how task manager is able to detect whether that is virtual machine or not? Can I know how can it be done?

virtualmachine

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,870 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,467 questions
0 comments No comments
{count} votes