欢迎来到天天文库
浏览记录
ID:13691880
大小:222.50 KB
页数:18页
时间:2018-07-23
《c#获取计算机系统信息的方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C#获取系统信息方法一:利用注册表获取//RegistryKey类所需要的包://RegistryKey类所需要的包:usingMicrosoft.Win32;//DllImport方法所需要的包:usingSystem.Runtime.InteropServices;//StringBuilder所需要的包:usingSystem.Text;//声明API函数 [DllImport("kernel32")] publicstaticexternvoidGetWindowsDirectory(StringB
2、uilderWinDir,intcount); [DllImport("kernel32")] publicstaticexternvoidGetSystemDirectory(StringBuilderSysDir,intcount); [DllImport("kernel32")] publicstaticexternvoidGetSystemInfo(refCPU_INFOcpuinfo); [DllImport("kernel32")] publicstati
3、cexternvoidGlobalMemoryStatus(refMEMORY_INFOmeminfo); [DllImport("kernel32")] publicstaticexternvoidGetSystemTime(refSYSTEMTIME_INFOstinfo); //定义以下各结构 //定义CPU的信息结构 [StructLayout(LayoutKind.Sequential)] publicstructCPU_INFO {
4、 publicuintdwOemId; publicuintdwPageSize; publicuintlpMinimumApplicationAddress; publicuintlpMaximumApplicationAddress; publicuintdwActiveProcessorMask; publicuintdwNumberOfProcessors; publicuintdwProcessor
5、Type; publicuintdwAllocationGranularity; publicuintdwProcessorLevel; publicuintdwProcessorRevision; } //定义内存的信息结构 [StructLayout(LayoutKind.Sequential)] publicstructMEMORY_INFO { publicuintdwLength;
6、 publicuintdwMemoryLoad; publicuintdwTotalPhys; publicuintdwAvailPhys; publicuintdwTotalPageFile; publicuintdwAvailPageFile; publicuintdwTotalVirtual; publicuintdwAvailVirtual; } //定义系统时间的信息结构
7、 [StructLayout(LayoutKind.Sequential)] publicstructSYSTEMTIME_INFO { publicushortwYear; publicushortwDay; publicushortwHour; publicushortwMinute; publicushortwSecond; publicushortwMilliseconds;
8、 } privatevoidinitSysInfoData() { //获取操作系统设置 lstSysInfo.Items.Add("计算机名:"+SystemInformation.ComputerName);
此文档下载收益归作者所有