简体   繁体   English

如何在C#中知道程序在运行XP SP2的Mac上的Parallels上运行,还是在运行Windows 7的Mac上的VmWare上运行

[英]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. 但是除此之外,我还必须知道它是Parallel还是VnWare。 Any idea? 任何想法? Thank you 谢谢

Base on the answer provided Final code will be like that, it works for me ok: 根据提供的答案,最终代码将是这样,它对我有效:

                using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
            {
                //TODO: Have to verify the difference between Parallel and Vm
                using (var items = searcher.Get())
                {
                    foreach (var item in items)
                    {
                        string manufacturer = item["Manufacturer"].ToString().ToLower();
                        string model = item["Model"].ToString().ToLower();
                        if (manufacturer.Contains("parallels") && model.Contains("parallels"))
                        {
                            Console.WriteLine("Parallels Detected");
                        }
                        else if(manufacturer.Contains("vmware"))
                        {
                            Console.WriteLine("VMWARE Detected");
                        }
                    }
                }
            }

Running this on VMware Fusion yields: 在VMware Fusion上运行此命令可获得:

Manufacturer: vmware, inc. 制造商:vmware,inc。
Model: VMware Virtual Platform 型号:VMware虚拟平台

Based on this , it looks like you would be safe checking whether Manufacturer or Model contains the string "parallels" to determine if it's running on parallels. 基于 ,看起来您可以安全地检查Manufacturer或Model是否包含字符串“ parallels”,以确定它是否在并行环境中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows XP上运行的ac#程序中进行图像扫描 - image scanning in a c# program running on Windows XP 在Windows 7上以Parallels 8错误运行C#Windows窗体应用程序 - Running a C# Windows Forms application on Windows 7 in Parallels 8 error 是否可以从 Visual Studio 编译 C# 程序以在 Mac 上运行? - Is it possible to compile a C# program from Visual Studio for running on Mac? 在 Mac 和 Winforms 上运行 Mono C# 项目 - Running Mono C# projects on Mac … and Winforms 我作为Windows服务运行的C#程序阻止Windows XP进入休眠状态 - My C# program running as Windows Service is blocking Windows XP from hibernation 关闭Windows XP后,C#应用程序继续运行 - C# application keep running after closing windows XP 在Windows XP计算机上运行SlimDX C#应用程序时遇到的麻烦 - troubles with running SlimDX C# application on Windows XP machine 如何在Windows XP SP2的IIS中运行.aspx页 - How to run .aspx page in IIS on Windows XP SP2 如何获取使用C#在Windows上运行的程序的名称 - How to get the name of program running on windows with c# 使用Mono在Mac上运行的C#应用​​程序中的文件访问问题 - File access issue in C# application running on mac using mono
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM