基本信息
源码名称:通过C#自带的头文件(类)获取Windows系统信息
源码大小:0.70M
文件格式:.zip
开发语言:C#
更新时间:2020-07-23
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
通过C#通过的类获取系统/硬件信息
通过C#通过的类获取系统/硬件信息
/* ******************************************************************************************* * 软件信息: * * 制作/更改时间:2020年7月23日19:08:58 * * 作者:gfdgd xi * * 程序编辑/调试平台(最近一次):Visual Studio 2019 Professional 以及 Windows 8.1 * * 程序目的:通过C#通过的类获取系统/硬件信息 * ******************************************************************************************* */ // 导入头文件 // using System.Collections.Generic; // using System.ComponentModel; // using System.Data; // using System.Drawing; // using System.Linq; // using System.Text; // 上面头文件可以不用,所以注释掉了 using System; using System.Windows.Forms; using System.Threading; using Microsoft.VisualBasic.Devices; namespace WindowsFormsApp4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; // 不让程序出现“Cross-thread operation not valid”错误 Thread thread = new Thread(start); thread.Start(); // 创建线程一个线程加载系统信息和工具箱列表 } private void start() // 这个线程用于加载系统信息和工具箱列表 { system.Items.Clear(); // 清空系统检测列表 /*通过ComputerInfo类获取系统信息 加载什么内容都标着*/ Computer info = new Computer(); system.Items.Add("系统全称:" info.Info.OSFullName); system.Items.Add("系统平台:" info.Info.OSPlatform); system.Items.Add("系统版本:" info.Info.OSVersion); system.Items.Add("计算机名:" info.Name); system.Items.Add("物理内存大小:" info.Info.TotalPhysicalMemory); system.Items.Add("虚拟内存大小:" info.Info.TotalVirtualMemory); system.Items.Add("数字锁定是否开启:" info.Keyboard.NumLock); system.Items.Add("大写锁定是否开启:" info.Keyboard.CapsLock); system.Items.Add("滚动锁定是否开启:" info.Keyboard.ScrollLock); system.Items.Add("鼠标是否开启了左右键调换:" info.Mouse.ButtonsSwapped); system.Items.Add("鼠标是否有滚轮:" info.Mouse.WheelExists); system.Items.Add("鼠标滚轮旋转一下所滚动的行数:" info.Mouse.WheelScrollLines); system.Items.Add("电脑是否连接网络:" info.Network.IsAvailable); system.Items.Add("主屏幕分辨率:" info.Screen.Bounds.Width "×" info.Screen.Bounds.Height); /*用Environment加载系统信息 加载什么内容都标着*/ system.Items.Add("CPU处理器数量:" Environment.ProcessorCount); system.Items.Add("64位操作系统:" Environment.Is64BitOperatingSystem); system.Items.Add("当前系统的SP版本:" Environment.OSVersion.ServicePack); system.Items.Add("系统目录所在位置:" Environment.SystemDirectory); system.Items.Add("当前登录用户名称:" Environment.UserName); var va = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User); system.Items.Add("—————当前用户环境变量列表—————"); // 获取用户环境变量列表 foreach(var k in va.Keys) { system.Items.Add(k.ToString() "=" va[k].ToString()); } system.Items.Add("————————————————————"); /*使用SystemInformation类获取用户信息 获取什么内容都标着*/ system.Items.Add("操作系统的启动方式:" SystemInformation.BootMode); system.Items.Add("窗口标题栏中按钮的标准尺寸:" SystemInformation.CaptionButtonSize.Width "×" SystemInformation.CaptionButtonSize.Height); system.Items.Add("窗口标题栏的标准高度:" SystemInformation.CaptionHeight); system.Items.Add("输入光标的闪烁时间:" SystemInformation.CaretBlinkTime); system.Items.Add("双击时,第一次点击和第二次点击最长的毫秒数:" SystemInformation.DoubleClickTime); system.Items.Add("是否启用高对比度模式:" SystemInformation.HighContrast); system.Items.Add("是否启用字体平滑:" SystemInformation.IsFontSmoothingEnabled); system.Items.Add("键盘重复速度设置:" SystemInformation.KeyboardSpeed); system.Items.Add("系统是否能使用希伯来语和阿拉伯语:" SystemInformation.MidEastEnabled); system.Items.Add("显示器数量:" SystemInformation.MonitorCount); system.Items.Add("鼠标的按键数:" SystemInformation.MouseButtons); system.Items.Add("获取当前鼠标的速度:" SystemInformation.MouseSpeed); system.Items.Add("当前电池状态:" SystemInformation.PowerStatus.BatteryChargeStatus); system.Items.Add("预计电池充满电的时间:" SystemInformation.PowerStatus.BatteryFullLifetime); system.Items.Add("电池剩余电量的百分比:" SystemInformation.PowerStatus.BatteryLifePercent); system.Items.Add("电池预计的使用时间:" SystemInformation.PowerStatus.BatteryLifeRemaining); system.Items.Add("当前的电源状态:" SystemInformation.PowerStatus.PowerLineStatus); switch(SystemInformation.ScreenOrientation) // 获取主屏幕的旋转度数 { case ScreenOrientation.Angle0: system.Items.Add("主屏幕旋转角度:0°"); break; case ScreenOrientation.Angle90: system.Items.Add("主屏幕旋转角度:90°"); break; case ScreenOrientation.Angle180: system.Items.Add("主屏幕旋转角度:180°"); break; case ScreenOrientation.Angle270: system.Items.Add("主屏幕旋转角度:270°"); break; default: system.Items.Add("主屏幕旋转角度:旋转角度未知(不明)"); break; } system.Items.Add("屏幕的工作区域:" SystemInformation.WorkingArea.Width "×" SystemInformation.WorkingArea.Height); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; // 先不让程序那么快退出 if (MessageBox.Show("你确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) // 判断用户是不是选择确定,如果选择了就 { e.Cancel = false; } } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { Close(); // 触发退出事件 } private void button1_Click(object sender, EventArgs e) { Thread thread = new Thread(start); thread.Start(); // 启动系统检测进程 } } }