[dllimport("kernel32")] public static extern void getwindowsdirectory(stringbuilder windir,int count); |
[dllimport("kernel32")] public static extern void getsystemdirectory(stringbuilder sysdir,int count); [dllimport("kernel32")] public static extern void getsysteminfo(ref cpu_info cpuinfo); [dllimport("kernel32")] public static extern void globalmemorystatus(ref memory_info meminfo); [dllimport("kernel32")] public static extern void getsystemtime(ref systemtime_info stinfo); |
//定义以下各结构 //定义cpu的信息结构 [structlayout(layoutkind.sequential)] public struct cpu_info { public uint dwoemid; public uint dwpagesize; public uint lpminimumapplicationaddress; public uint lpmaximumapplicationaddress; public uint dwactiveprocessormask; public uint dwnumberofprocessors; public uint dwprocessortype; public uint dwallocationgranularity; public uint dwprocessorlevel; public uint dwprocessorrevision; } //定义内存的信息结构 [structlayout(layoutkind.sequential)] public struct memory_info { public uint dwlength; public uint dwmemoryload; public uint dwtotalphys; public uint dwavailphys; public uint dwtotalpagefile; public uint dwavailpagefile; public uint dwtotalvirtual; public uint dwavailvirtual; } //定义系统时间的信息结构 [structlayout(layoutkind.sequential)] public struct systemtime_info { public ushort wyear; public ushort wmonth; public ushort wdayofweek; public ushort wday; public ushort whour; public ushort wminute; public ushort wsecond; public ushort wmilliseconds; } |
private void getinfo_click(object sender, system.eventargs e) { //调用getwindowsdirectory和getsystemdirectory函数分别取得windows路径和系统路径 const int nchars = 128; stringbuilder buff = new stringbuilder(nchars); getwindowsdirectory(buff,nchars); windowsdirectory.text = "windows路径:"+buff.tostring(); getsystemdirectory(buff,nchars); systemdirectory.text = "系统路径:"+buff.tostring(); //调用getsysteminfo函数获取cpu的相关信息 cpu_info cpuinfo; cpuinfo = new cpu_info(); getsysteminfo(ref cpuinfo); numberofprocessors.text = "本计算机中有"+cpuinfo.dwnumberofprocessors.tostring()+"个cpu"; processortype.text = "cpu的类型为"+cpuinfo.dwprocessortype.tostring(); processorlevel.text = "cpu等级为"+cpuinfo.dwprocessorlevel.tostring(); oemid.text = "cpu的oem id为"+cpuinfo.dwoemid.tostring(); pagesize.text = "cpu中的页面大小为"+cpuinfo.dwpagesize.tostring(); //调用globalmemorystatus函数获取内存的相关信息 memory_info meminfo; meminfo = new memory_info(); globalmemorystatus(ref meminfo); memoryload.text = meminfo.dwmemoryload.tostring()+"%的内存正在使用"; totalphys.text = "物理内存共有"+meminfo.dwtotalphys.tostring()+"字节"; availphys.text = "可使用的物理内存有"+meminfo.dwavailphys.tostring()+"字节"; totalpagefile.text = "交换文件总大小为"+meminfo.dwtotalpagefile.tostring()+"字节"; availpagefile.text = "尚可交换文件大小为"+meminfo.dwavailpagefile.tostring()+"字节"; totalvirtual.text = "总虚拟内存有"+meminfo.dwtotalvirtual.tostring()+"字节"; availvirtual.text = "未用虚拟内存有"+meminfo.dwavailvirtual.tostring()+"字节"; //调用getsystemtime函数获取系统时间信息 systemtime_info stinfo; stinfo = new systemtime_info(); getsystemtime(ref stinfo); date.text = stinfo.wyear.tostring()+"年"+stinfo.wmonth.tostring()+"月"+stinfo.wday.tostring()+"日"; time.text = (stinfo.whour+8).tostring()+"点"+stinfo.wminute.tostring()+"分"+stinfo.wsecond.tostring()+"秒"; } |
新闻热点
疑难解答