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