- 【本机IP地址】
- 第一种方法:
- IPHostEntry hostentry = Dns.Resolve(Dns.GetHostName());
- IPAddress address=hostentry.AddressList[0];
- 第二种方法:
- Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
- 【判断当前用户是否连网】
- PingReply reply = new Ping().Send(address);
- if (reply.Status == IPStatus.Success)
- MessageBox.Show("Ping successfully.");
- else
- MessageBox.Show("Ping failure.");
- 【获取当前客户端硬盘盘符】
- string[] mydrivers = Directory.GetLogicalDrives();
- 【判断客户端移动硬盘、硬盘】
- SelectQuery select = new SelectQuery("select * from win32_logicaldisk");
- ManagementObjectSearcher mos = new ManagementObjectSearcher(select);
- foreach (ManagementObject disk in mos.Get())
- {
- string msg = disk["Name"].ToString();
- DriveInfo info = new DriveInfo(msg);
- switch (info.DriveType.ToString())
- {
- case "Unknown":
- label1.Text += msg + "这是未知设备__";
- break;
- case "NoRootDirectory":
- label1.Text += msg + "这是未分区__";
- break;
- case "Removable":
- label1.Text += msg + "这是可以动磁盘__";
- break;
- case "Fixed":
- label1.Text += msg + "这是硬盘__";
- break;
- case "Network":
- label1.Text += msg + "这是网络驱动器__";
- break;
- case "CDRom":
- label1.Text += msg + "这是光驱__";
- break;
- }
- }
- 【获取当前显示的长宽】
- 宽:Screen.PrimaryScreen.WorkingArea.Width
- 长:Screen.PrimaryScreen.WorkingArea.Height
- 【获取客户端进程信息】
- System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
- 【关闭进程信息】
- foreach (System.Diagnostics.Process p in processes)
- {
- if (p.ProcessName == "IntelliTrace")
- {
- p.Kill();
- }
- }
- 【判断客户端是否安装声卡】
- [DllImport("winmm.dll", EntryPoint = "waveOutGetNumDevs")]
- public static extern int waveOutGetNumDevs();
- private void button1_Click(object sender, EventArgs e)
- {
- if (waveOutGetNumDevs() != 0)
- {
- MessageBox.Show("已经安装声卡");
- }
- else {
- MessageBox.Show("未安装声卡");
- }
- }
- 【获取计算机名称和当前登录用户】
- 计算机名称:
- Dns.GetHostName();
- 当前登录用户:
- Environment.GetEnvironmentVariable("UserName");
C# 本地环境检测常用Code
最新推荐文章于 2022-07-03 22:30:42 发布