C#實現(xiàn)獲取運行平臺系統(tǒng)信息的方法
更新時間:2014年07月29日 09:53:11 投稿:shichen2014
這篇文章主要介紹了C#實現(xiàn)獲取運行平臺系統(tǒng)信息的方法,比較典型的C#應用,需要的朋友可以參考下
本文實例講述了C#獲取運行平臺系統(tǒng)信息的方法,主要可以實現(xiàn)C#獲取系統(tǒng)啟動經(jīng)過的毫秒數(shù),相連網(wǎng)絡域名,系統(tǒng)啟動經(jīng)過的毫秒數(shù)等,并有關于ListView控件的相關操作。
具體的實現(xiàn)代碼如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 獲取系統(tǒng)環(huán)境和平臺信息
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的代碼
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(48, 224);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 32);
this.button1.TabIndex = 4;
this.button1.Text = "獲取";
this.button1.Click += new System.EventHandler(this.button1_Click);
// button2
this.button2.Location = new System.Drawing.Point(184, 224);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 32);
this.button2.TabIndex = 5;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listView1
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(16, 24);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(256, 184);
this.listView1.TabIndex = 6;
this.listView1.View = System.Windows.Forms.View.Details;
// columnHeader1
this.columnHeader1.Text = "屬性";
this.columnHeader1.Width = 100;
// columnHeader2
this.columnHeader2.Text = "值";
this.columnHeader2.Width = 175;
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "獲取系統(tǒng)環(huán)境和平臺信息";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
// 關閉當前窗體
this.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
listView1.Items.Clear(); // 清除ListView控件中的項
ListViewItem listViewItem;
try
{
// 加入計算機名
listViewItem = new ListViewItem("計算機名", 0);
listViewItem.SubItems.Add(Environment.MachineName);
listView1.Items.Add(listViewItem);
// 加入當前平臺名
listViewItem = new ListViewItem("當前平臺名", 0);
listViewItem.SubItems.Add(Environment.OSVersion.Platform.ToString());
listView1.Items.Add(listViewItem);
// 加入平臺版本號
listViewItem = new ListViewItem("平臺版本號", 0);
listViewItem.SubItems.Add(Environment.OSVersion.Version.ToString());
listView1.Items.Add(listViewItem);
// 與系統(tǒng)相連的網(wǎng)絡名
listViewItem = new ListViewItem("相連網(wǎng)絡域名", 0);
listViewItem.SubItems.Add(Environment.UserDomainName);
listView1.Items.Add(listViewItem);
// 系統(tǒng)目錄路徑
listViewItem = new ListViewItem("系統(tǒng)啟動經(jīng)過的毫秒數(shù)", 0);
listViewItem.SubItems.Add(Environment.SystemDirectory );
listView1.Items.Add(listViewItem);
// 系統(tǒng)當前時間
listViewItem = new ListViewItem("系統(tǒng)當前時間", 0);
listViewItem.SubItems.Add(DateTime.Now.ToString());
listView1.Items.Add(listViewItem);
// 系統(tǒng)啟動后經(jīng)過的毫秒數(shù)
listViewItem = new ListViewItem("系統(tǒng)啟動經(jīng)過的毫秒數(shù)", 0);
listViewItem.SubItems.Add(Environment.TickCount.ToString());
listView1.Items.Add(listViewItem);
}
catch(Exception exc)
{
MessageBox.Show(exc.Message, "提示");
}
}
// 為避免編寫的代碼冗長,添加 AddItem 方法
public void AddItem(string sItem)
{
// 添加項 sItem 到 listView1 中
listView1.Items.Add(sItem);
}
}
}
您可能感興趣的文章:
- C#實現(xiàn)的Socket服務器端、客戶端代碼分享
- 在C#中對TCP客戶端的狀態(tài)封裝詳解
- C#用Activex實現(xiàn)Web客戶端讀取RFID功能的代碼
- c# socket編程udp客戶端實現(xiàn)代碼分享
- 獲取客戶端IP地址c#/vb.net各自實現(xiàn)代碼
- 分享用于操作FTP的客戶端C#類
- C#如何取硬件標志
- 使用C#配合ArcGIS Engine進行地理信息系統(tǒng)開發(fā)
- C# 當前系統(tǒng)時間獲取及時間格式詳解
- 使用C#獲取系統(tǒng)特殊文件夾路徑的解決方法
- C#獲取系統(tǒng)版本信息方法
- C# 獲取系統(tǒng)進程的用戶名
- C#編程獲取客戶端計算機硬件及系統(tǒng)信息功能示例
相關文章
asp.net(C#)清除全部Session與單個Session的方法
下面小編就為大家?guī)硪黄猘sp.net(C#)清除全部Session與單個Session的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12

