• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#获取系统信息

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  public string GetMyOSName()
        {
            //获取当前操作系统信息
            OperatingSystem MyOS = Environment.OSVersion;
            string MyOSName = "";
            //如果版本号是 5, 则它应该是 Win2K, XP或2003
            if (MyOS.Version.Major == 5)
            {
                switch (MyOS.Version.Minor)
                {
                    case 0:
                        MyOSName = "Windows 2000";
                        break;
                    case 1:
                        MyOSName = "Windows XP";
                        break;
                    case 2:
                        MyOSName = "Windows Server 2003";
                        break;
                    default:
                        MyOSName = MyOS.ToString();
                        break;
                }
            }
            else
            {
                // 可能是 NT4
                MyOSName = MyOS.VersionString;
            }
            //获取SP信息
            string MySPName = MyOS.ServicePack;
            return MyOSName + " " + MySPName;
        }
        public string GetMyComputerName()
        {//获取当前计算机名称
            string MyComputerName = Environment.GetEnvironmentVariable("ComputerName");
            return MyComputerName;
        }
        public string GetMyUserName()
        {//获取当前用户名称
            string MyUserName = Environment.GetEnvironmentVariable("UserName");
            return MyUserName;
        }
        public string GetMyPaths()
        {//获取当前系统默认路径配置信息,环境变量
            string MyPaths = Environment.GetEnvironmentVariable("Path");
            return MyPaths;
        }
        public string GetMyDriveInfo()
        {//获取驱动器的存储空间大小
            string[] MyDrive = Environment.GetLogicalDrives();
            long s0 = 0, s1 = 0;
            foreach (string MyDriveLetter in MyDrive)
            {
                try
                {
                    DriveInfo MyDriveInfo = new DriveInfo(MyDriveLetter);
                    if (MyDriveInfo.DriveType == DriveType.CDRom || MyDriveInfo.DriveType == DriveType.Removable)
                        continue;
                    s0 += MyDriveInfo.TotalSize;
                    s1 += MyDriveInfo.TotalFreeSpace;
                }
                catch { }
            }
            return (s1 / 1073741824).ToString() + "G/" + (s0 / 1073741824).ToString() + "G";
        }

        public string GetMyMemoryInfo()
        {//获取当前计算机的内存信息
            try
            {
                Microsoft.VisualBasic.Devices.Computer My = new Microsoft.VisualBasic.Devices.Computer();
                return (My.Info.AvailablePhysicalMemory / 1024 / 1024).ToString() + "M/" + (My.Info.TotalPhysicalMemory / 1024 / 1024).ToString() + "M";
            }
            catch
            {
                return "";
            }
        }
        public string GetMyScreens()
        {//获取计算机的显示设备信息
            Screen[] MyScreens = Screen.AllScreens;
            int MyBound = MyScreens.GetUpperBound(0);
            return MyScreens[0].DeviceName;
            /*
            string MyInfo = "";
            for (int i = 0; i <= MyBound; i++)
            {
                MyInfo += "\n显示边界: " + MyScreens[i].Bounds.ToString();
                MyInfo += "\n显示器工作区: " + MyScreens[i].WorkingArea.ToString();
                MyInfo += "\n是否是主显示器: " + MyScreens[i].Primary.ToString();
                MyInfo += "\n显示设备名称: " + MyScreens[i].DeviceName;
            }
            */
        }
        public string GetMyCpuInfo()
        {
            RegistryKey reg = Registry.LocalMachine;
            reg = reg.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            return reg.GetValue("ProcessorNameString").ToString();
        }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#查看电脑内存发布时间:2022-07-14
下一篇:
C#基础之二(数据类型)发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap