vendredi 27 février 2015

How to know in C# that program is running on Parallels on a Mac running XP SP2 or VmWare on a Mac running Windows 7

I am using the following code to indicate if code is executed on virtual machine.



using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
{
using (var items = searcher.Get())
{
foreach (var item in items)
{
string manufacturer = item["Manufacturer"].ToString().ToLower();
Console.WriteLine("Manufacturer: " + manufacturer);
Console.WriteLine("Model: " + item["Model"].ToString());
if ((manufacturer == "microsoft corporation" && item["Model"].ToString().ToUpperInvariant().Contains("VIRTUAL"))
|| manufacturer.Contains("vmware")
|| item["Model"].ToString() == "VirtualBox")
{
Console.WriteLine("Manufacturer: " + manufacturer);
Console.WriteLine("Model: " + item["Model"].ToString());
}
}
}
}
Console.Read();


But in addition to that I have to know if it is a Parallel or VnWare. Any idea? Thank you


Aucun commentaire:

Enregistrer un commentaire