vendredi 27 février 2015

How to indicate in C# that application is running on Parallels or VmWare on Mac

Hi 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();


What ManagementObjectSearcher parameter could be use to indicate is it Parallels on a Mac running XP SP2 or VmWare on a Mac running Windows 7


Aucun commentaire:

Enregistrer un commentaire