C#使用System.Environment获取电脑的相关属性
程序员文章站
2023-12-09 18:53:27
使用system.environment获取电脑的相关属性,入门案例,具体内容如下
static void main(string[] args)
{...
使用system.environment获取电脑的相关属性,入门案例,具体内容如下
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); } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。