使用System.Environment获取电脑的相关属性,入门案例,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
static void Main( string [] args)
{
MyComputer myNotebook = new MyComputer();
myNotebook.ComputerInfo();
Console.ReadKey();
}
public class MyComputer
{
private string Domain;
private string No;
private string User;
private string [] Drives;
private string OS;
private Version Version;
private int ProcessorCount;
public string Name
{
get
{
return this .No;
}
}
public MyComputer()
{
this .User = System.Environment.UserName;
this .No = System.Environment.MachineName;
this .Domain = System.Environment.UserDomainName;
this .Drives = System.Environment.GetLogicalDrives();
this .OS = System.Environment.OSVersion.ToString();
this .Version = System.Environment.Version;
this .ProcessorCount = System.Environment.ProcessorCount;
}
public void ComputerInfo()
{
Console.WriteLine( "当前电脑所在的域名:{0}" , Domain);
Console.WriteLine( "当前电脑的用户是:{0}" , User);
Console.WriteLine( "当前电脑的名字是:{0}" , No);
Console.WriteLine( "当前电脑的操作系统版本:{0}" , OS);
Console.WriteLine( "当前电脑的系统版本:{0}" , Version);
Console.WriteLine( "当前电脑的处理器个数:{0}" , ProcessorCount);
Console.WriteLine( "当前电脑的驱动器有:" );
foreach (var item in Drives)
{
Console.WriteLine( "{0}驱动器下的目录有:" , item);
Console.WriteLine( "=========================================================" );
string [] d = Directory.GetDirectories(item);
foreach (var d1 in d)
{
Console.WriteLine(d1);
}
}
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/ChengWenHao/p/GetComputerInfo.html