C#使用System.Environment获取电脑的相关属性
使用System.Environ【文章原创作者:http://www.yidunidc.com/st.html转发请说明出处】ment获取电脑的相关属性,入门案例,具体内容如下
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); } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持海外IDC网。