using
System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
namespace GetSystemInfoDemo
... {
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label AvailVirtual;
private System.Windows.Forms.Label TotalVirtual;
private System.Windows.Forms.Label AvailPageFile;
private System.Windows.Forms.Label TotalPageFile;
private System.Windows.Forms.Label AvailPhys;
private System.Windows.Forms.Label TotalPhys;
private System.Windows.Forms.Label MemoryLoad;
private System.Windows.Forms.Label PageSize;
private System.Windows.Forms.Label OemId;
private System.Windows.Forms.Label ProcessorLevel;
private System.Windows.Forms.Label ProcessorType;
private System.Windows.Forms.Label NumberOfProcessors;
private System.Windows.Forms.Label SystemDirectory;
private System.Windows.Forms.Label WindowsDirectory;
private System.Windows.Forms.Label Time;
private System.Windows.Forms.Label Date;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[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);
[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;
}
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
...{
if (disposing)
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose(disposing);
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.Date = new System.Windows.Forms.Label();
this.Time = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.TotalVirtual = new System.Windows.Forms.Label();
this.AvailVirtual = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.ProcessorType = new System.Windows.Forms.Label();
this.NumberOfProcessors = new System.Windows.Forms.Label();
this.MemoryLoad = new System.Windows.Forms.Label();
this.PageSize = new System.Windows.Forms.Label();
this.OemId = new System.Windows.Forms.Label();
this.ProcessorLevel = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.AvailPageFile = new System.Windows.Forms.Label();
this.TotalPageFile = new System.Windows.Forms.Label();
this.AvailPhys = new System.Windows.Forms.Label();
this.TotalPhys = new System.Windows.Forms.Label();
this.WindowsDirectory = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SystemDirectory = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.Date);
this.groupBox1.Controls.Add(this.Time);
this.groupBox1.Location = new System.Drawing.Point(7, 17);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 137);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// Date
//
this.Date.Location = new System.Drawing.Point(27, 103);
this.Date.Name = "Date";
this.Date.Size = new System.Drawing.Size(133, 24);
this.Date.TabIndex = 1;
this.Date.Text = "label2";
//
// Time
//
this.Time.Location = new System.Drawing.Point(27, 51);
this.Time.Name = "Time";
this.Time.Size = new System.Drawing.Size(133, 25);
this.Time.TabIndex = 0;
this.Time.Text = "label1";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.TotalVirtual);
this.groupBox2.Controls.Add(this.AvailVirtual);
this.groupBox2.Location = new System.Drawing.Point(247, 26);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(200, 128);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "groupBox2";
//
// TotalVirtual
//
this.TotalVirtual.Location = new System.Drawing.Point(33, 43);
this.TotalVirtual.Name = "TotalVirtual";
this.TotalVirtual.Size = new System.Drawing.Size(140, 24);
this.TotalVirtual.TabIndex = 5;
this.TotalVirtual.Text = "label6";
//
// AvailVirtual
//
this.AvailVirtual.Location = new System.Drawing.Point(33, 86);
this.AvailVirtual.Name = "AvailVirtual";
this.AvailVirtual.Size = new System.Drawing.Size(140, 24);
this.AvailVirtual.TabIndex = 10;
this.AvailVirtual.Text = "label11";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.ProcessorType);
this.groupBox3.Controls.Add(this.NumberOfProcessors);
this.groupBox3.Controls.Add(this.MemoryLoad);
this.groupBox3.Controls.Add(this.PageSize);
this.groupBox3.Controls.Add(this.OemId);
this.groupBox3.Controls.Add(this.ProcessorLevel);
this.groupBox3.Location = new System.Drawing.Point(247, 171);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 275);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "groupBox2";
//
// ProcessorType
//
this.ProcessorType.Location = new System.Drawing.Point(33, 231);
this.ProcessorType.Name = "ProcessorType";
this.ProcessorType.Size = new System.Drawing.Size(140, 25);
this.ProcessorType.TabIndex = 13;
this.ProcessorType.Text = "label2";
//
// NumberOfProcessors
//
this.NumberOfProcessors.Location = new System.Drawing.Point(33, 26);
this.NumberOfProcessors.Name = "NumberOfProcessors";
this.NumberOfProcessors.Size = new System.Drawing.Size(140, 24);
this.NumberOfProcessors.TabIndex = 12;
this.NumberOfProcessors.Text = "label1";
//
// MemoryLoad
//
this.MemoryLoad.Location = new System.Drawing.Point(33, 60);
this.MemoryLoad.Name = "MemoryLoad";
this.MemoryLoad.Size = new System.Drawing.Size(140, 25);
this.MemoryLoad.TabIndex = 3;
this.MemoryLoad.Text = "label4";
//
// PageSize
//
this.PageSize.Location = new System.Drawing.Point(33, 103);
this.PageSize.Name = "PageSize";
this.PageSize.Size = new System.Drawing.Size(140, 24);
this.PageSize.TabIndex = 8;
this.PageSize.Text = "label9";
//
// OemId
//
this.OemId.Location = new System.Drawing.Point(33, 154);
this.OemId.Name = "OemId";
this.OemId.Size = new System.Drawing.Size(140, 25);
this.OemId.TabIndex = 9;
this.OemId.Text = "label10";
//
// ProcessorLevel
//
this.ProcessorLevel.Location = new System.Drawing.Point(33, 197);
this.ProcessorLevel.Name = "ProcessorLevel";
this.ProcessorLevel.Size = new System.Drawing.Size(140, 25);
this.ProcessorLevel.TabIndex = 11;
this.ProcessorLevel.Text = "label12";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.AvailPageFile);
this.groupBox4.Controls.Add(this.TotalPageFile);
this.groupBox4.Controls.Add(this.AvailPhys);
this.groupBox4.Controls.Add(this.TotalPhys);
this.groupBox4.Controls.Add(this.WindowsDirectory);
this.groupBox4.Location = new System.Drawing.Point(13, 171);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(200, 318);
this.groupBox4.TabIndex = 2;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "groupBox2";
//
// AvailPageFile
//
this.AvailPageFile.Location = new System.Drawing.Point(27, 69);
this.AvailPageFile.Name = "AvailPageFile";
this.AvailPageFile.Size = new System.Drawing.Size(133, 24);
this.AvailPageFile.TabIndex = 4;
this.AvailPageFile.Text = "label5";
//
// TotalPageFile
//
this.TotalPageFile.Location = new System.Drawing.Point(27, 120);
this.TotalPageFile.Name = "TotalPageFile";
this.TotalPageFile.Size = new System.Drawing.Size(133, 25);
this.TotalPageFile.TabIndex = 7;
this.TotalPageFile.Text = "label8";
//
// AvailPhys
//
this.AvailPhys.Location = new System.Drawing.Point(27, 171);
this.AvailPhys.Name = "AvailPhys";
this.AvailPhys.Size = new System.Drawing.Size(133, 25);
this.AvailPhys.TabIndex = 6;
this.AvailPhys.Text = "label7";
//
// TotalPhys
//
this.TotalPhys.Location = new System.Drawing.Point(27, 223);
this.TotalPhys.Name = "TotalPhys";
this.TotalPhys.Size = new System.Drawing.Size(133, 24);
this.TotalPhys.TabIndex = 2;
this.TotalPhys.Text = "label3";
//
// WindowsDirectory
//
this.WindowsDirectory.Location = new System.Drawing.Point(27, 26);
this.WindowsDirectory.Name = "WindowsDirectory";
this.WindowsDirectory.Size = new System.Drawing.Size(133, 24);
this.WindowsDirectory.TabIndex = 11;
this.WindowsDirectory.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(207, 489);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(62, 24);
this.button1.TabIndex = 3;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// SystemDirectory
//
this.SystemDirectory.Location = new System.Drawing.Point(27, 429);
this.SystemDirectory.Name = "SystemDirectory";
this.SystemDirectory.Size = new System.Drawing.Size(83, 24);
this.SystemDirectory.TabIndex = 2;
this.SystemDirectory.Text = "label2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(488, 507);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.SystemDirectory);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void button1_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() + "秒";
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
namespace GetSystemInfoDemo
... {
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label AvailVirtual;
private System.Windows.Forms.Label TotalVirtual;
private System.Windows.Forms.Label AvailPageFile;
private System.Windows.Forms.Label TotalPageFile;
private System.Windows.Forms.Label AvailPhys;
private System.Windows.Forms.Label TotalPhys;
private System.Windows.Forms.Label MemoryLoad;
private System.Windows.Forms.Label PageSize;
private System.Windows.Forms.Label OemId;
private System.Windows.Forms.Label ProcessorLevel;
private System.Windows.Forms.Label ProcessorType;
private System.Windows.Forms.Label NumberOfProcessors;
private System.Windows.Forms.Label SystemDirectory;
private System.Windows.Forms.Label WindowsDirectory;
private System.Windows.Forms.Label Time;
private System.Windows.Forms.Label Date;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[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);
[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;
}
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
...{
if (disposing)
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose(disposing);
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.Date = new System.Windows.Forms.Label();
this.Time = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.TotalVirtual = new System.Windows.Forms.Label();
this.AvailVirtual = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.ProcessorType = new System.Windows.Forms.Label();
this.NumberOfProcessors = new System.Windows.Forms.Label();
this.MemoryLoad = new System.Windows.Forms.Label();
this.PageSize = new System.Windows.Forms.Label();
this.OemId = new System.Windows.Forms.Label();
this.ProcessorLevel = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.AvailPageFile = new System.Windows.Forms.Label();
this.TotalPageFile = new System.Windows.Forms.Label();
this.AvailPhys = new System.Windows.Forms.Label();
this.TotalPhys = new System.Windows.Forms.Label();
this.WindowsDirectory = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SystemDirectory = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.Date);
this.groupBox1.Controls.Add(this.Time);
this.groupBox1.Location = new System.Drawing.Point(7, 17);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 137);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// Date
//
this.Date.Location = new System.Drawing.Point(27, 103);
this.Date.Name = "Date";
this.Date.Size = new System.Drawing.Size(133, 24);
this.Date.TabIndex = 1;
this.Date.Text = "label2";
//
// Time
//
this.Time.Location = new System.Drawing.Point(27, 51);
this.Time.Name = "Time";
this.Time.Size = new System.Drawing.Size(133, 25);
this.Time.TabIndex = 0;
this.Time.Text = "label1";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.TotalVirtual);
this.groupBox2.Controls.Add(this.AvailVirtual);
this.groupBox2.Location = new System.Drawing.Point(247, 26);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(200, 128);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "groupBox2";
//
// TotalVirtual
//
this.TotalVirtual.Location = new System.Drawing.Point(33, 43);
this.TotalVirtual.Name = "TotalVirtual";
this.TotalVirtual.Size = new System.Drawing.Size(140, 24);
this.TotalVirtual.TabIndex = 5;
this.TotalVirtual.Text = "label6";
//
// AvailVirtual
//
this.AvailVirtual.Location = new System.Drawing.Point(33, 86);
this.AvailVirtual.Name = "AvailVirtual";
this.AvailVirtual.Size = new System.Drawing.Size(140, 24);
this.AvailVirtual.TabIndex = 10;
this.AvailVirtual.Text = "label11";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.ProcessorType);
this.groupBox3.Controls.Add(this.NumberOfProcessors);
this.groupBox3.Controls.Add(this.MemoryLoad);
this.groupBox3.Controls.Add(this.PageSize);
this.groupBox3.Controls.Add(this.OemId);
this.groupBox3.Controls.Add(this.ProcessorLevel);
this.groupBox3.Location = new System.Drawing.Point(247, 171);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 275);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "groupBox2";
//
// ProcessorType
//
this.ProcessorType.Location = new System.Drawing.Point(33, 231);
this.ProcessorType.Name = "ProcessorType";
this.ProcessorType.Size = new System.Drawing.Size(140, 25);
this.ProcessorType.TabIndex = 13;
this.ProcessorType.Text = "label2";
//
// NumberOfProcessors
//
this.NumberOfProcessors.Location = new System.Drawing.Point(33, 26);
this.NumberOfProcessors.Name = "NumberOfProcessors";
this.NumberOfProcessors.Size = new System.Drawing.Size(140, 24);
this.NumberOfProcessors.TabIndex = 12;
this.NumberOfProcessors.Text = "label1";
//
// MemoryLoad
//
this.MemoryLoad.Location = new System.Drawing.Point(33, 60);
this.MemoryLoad.Name = "MemoryLoad";
this.MemoryLoad.Size = new System.Drawing.Size(140, 25);
this.MemoryLoad.TabIndex = 3;
this.MemoryLoad.Text = "label4";
//
// PageSize
//
this.PageSize.Location = new System.Drawing.Point(33, 103);
this.PageSize.Name = "PageSize";
this.PageSize.Size = new System.Drawing.Size(140, 24);
this.PageSize.TabIndex = 8;
this.PageSize.Text = "label9";
//
// OemId
//
this.OemId.Location = new System.Drawing.Point(33, 154);
this.OemId.Name = "OemId";
this.OemId.Size = new System.Drawing.Size(140, 25);
this.OemId.TabIndex = 9;
this.OemId.Text = "label10";
//
// ProcessorLevel
//
this.ProcessorLevel.Location = new System.Drawing.Point(33, 197);
this.ProcessorLevel.Name = "ProcessorLevel";
this.ProcessorLevel.Size = new System.Drawing.Size(140, 25);
this.ProcessorLevel.TabIndex = 11;
this.ProcessorLevel.Text = "label12";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.AvailPageFile);
this.groupBox4.Controls.Add(this.TotalPageFile);
this.groupBox4.Controls.Add(this.AvailPhys);
this.groupBox4.Controls.Add(this.TotalPhys);
this.groupBox4.Controls.Add(this.WindowsDirectory);
this.groupBox4.Location = new System.Drawing.Point(13, 171);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(200, 318);
this.groupBox4.TabIndex = 2;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "groupBox2";
//
// AvailPageFile
//
this.AvailPageFile.Location = new System.Drawing.Point(27, 69);
this.AvailPageFile.Name = "AvailPageFile";
this.AvailPageFile.Size = new System.Drawing.Size(133, 24);
this.AvailPageFile.TabIndex = 4;
this.AvailPageFile.Text = "label5";
//
// TotalPageFile
//
this.TotalPageFile.Location = new System.Drawing.Point(27, 120);
this.TotalPageFile.Name = "TotalPageFile";
this.TotalPageFile.Size = new System.Drawing.Size(133, 25);
this.TotalPageFile.TabIndex = 7;
this.TotalPageFile.Text = "label8";
//
// AvailPhys
//
this.AvailPhys.Location = new System.Drawing.Point(27, 171);
this.AvailPhys.Name = "AvailPhys";
this.AvailPhys.Size = new System.Drawing.Size(133, 25);
this.AvailPhys.TabIndex = 6;
this.AvailPhys.Text = "label7";
//
// TotalPhys
//
this.TotalPhys.Location = new System.Drawing.Point(27, 223);
this.TotalPhys.Name = "TotalPhys";
this.TotalPhys.Size = new System.Drawing.Size(133, 24);
this.TotalPhys.TabIndex = 2;
this.TotalPhys.Text = "label3";
//
// WindowsDirectory
//
this.WindowsDirectory.Location = new System.Drawing.Point(27, 26);
this.WindowsDirectory.Name = "WindowsDirectory";
this.WindowsDirectory.Size = new System.Drawing.Size(133, 24);
this.WindowsDirectory.TabIndex = 11;
this.WindowsDirectory.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(207, 489);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(62, 24);
this.button1.TabIndex = 3;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// SystemDirectory
//
this.SystemDirectory.Location = new System.Drawing.Point(27, 429);
this.SystemDirectory.Name = "SystemDirectory";
this.SystemDirectory.Size = new System.Drawing.Size(83, 24);
this.SystemDirectory.TabIndex = 2;
this.SystemDirectory.Text = "label2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(488, 507);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.SystemDirectory);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
private void button1_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() + "秒";
}
}
}
本文轉自: http://www.cnblogs.com/jhtchina/archive/2006/02/21/334855.html