A simple Go program that detects whether the current Windows system is running inside a Hyper-V virtual machine environment(Guest) using CPUID instruction.
go install github.com/gmh5225/Go-Detection-Hyper-v@v0.0.5
where/which Go-Detection-Hyper-v
go clean -modcache
The program uses the CPUID instruction to:
- Check for the Hyper-V vendor string ("Microsoft Hv")
- Verify specific feature flags that indicate a Hyper-V environment
main.go
- Main program logic and Hyper-V detection implementationcpuid_amd64.s
- Assembly code for CPUID instruction
The detection is performed by:
- Using CPUID with leaf
0x40000000
to check for Hyper-V vendor signature - Using CPUID with leaf
0x40000003
to verify specific feature flags
The program will output one of two messages:
- "Running in Hyper-V environment(Guest)"
- "Not running in Hyper-V environment(Guest)"