直接贴代码了:

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("当前操作系统: " + GetOSName());

            Console.WriteLine("\n当前操作系统的版本:" + Environment.OSVersion.VersionString);

            Console.WriteLine("\n机器名:" + Environment.MachineName);

            Console.WriteLine("\n当前已登录到 Windows 操作系统的人员的用户名:" + Environment.UserName);

            Console.WriteLine("\n当前计算机上的处理器数:" + Environment.ProcessorCount);

            Console.WriteLine("\n当前操作系统是否为 64 位操作系统?   答:" + (Environment.Is64BitOperatingSystem ? "" : ""));

            Console.WriteLine("\n当前进程是否为 64 位进程?   答:" + (Environment.Is64BitProcess ? "" : ""));
        }


        /// <summary>
        /// 得到当前正在运行的操作系统的名称。 比如: 
        /// "Microsoft Windows 7 Enterprise".
        /// </summary>
        /// <returns></returns>
        static string GetOSName()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT Caption FROM Win32_OperatingSystem");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                return queryObj["Caption"] as string;
            }

            return null;
        }
    }

 

运行截图:

C# 中得到当前操作系统、操作系统的版本、.NET 运行环境等信息

谢谢浏览!

相关文章:

  • 2021-10-18
  • 2021-05-29
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-12-09
  • 2021-09-30
  • 2021-12-20
  • 2022-12-23
  • 2021-06-06
  • 2022-01-21
  • 2021-12-05
相关资源
相似解决方案