image

   1: label1.Text = "目前系統目錄為:" + Environment.SystemDirectory;//顯示系統目錄

---------------------------------------------------------------------------------------------------------------------------

image

   1: label1.Text = "機器名稱為:" + Environment.MachineName;//顯示機器名稱

---------------------------------------------------------------------------------------------------------------------------

抓取目前目錄夾位置

   1: richTextBox1.Text = "目前程式執行目錄:" + Environment.CurrentDirectory;//取得目前程式執行目錄

---------------------------------------------------------------------------------------------------------------------------

image

   1: label1.Text = "系統版本號:" + Environment.OSVersion.VersionString;//顯示系統版本號

---------------------------------------------------------------------------------------------------------------------------

顯示提示

image

   1: toolTip1.InitialDelay = 1000;//設定在顯示之前經過的時間
   2: toolTip1.ReshowDelay = 500;//設定出現提示視窗出現的時間            
   3: toolTip1.ShowAlways = true;//設定是否顯示提示視窗
   4: toolTip1.SetToolTip(this.groupBox1, "提示有變化嗎?");//設定提示文字與控制元件關聯

---------------------------------------------------------------------------------------------------------------------------

image

   1: listView1.View = View.Details;//設定控制元件顯示方式
   2: listView1.GridLines = true;//是否顯示網格
   3: listView1.Columns.Add("環境變數", 150, HorizontalAlignment.Left);//新增列標頭
   4: listView1.Columns.Add("變數值", 150, HorizontalAlignment.Left);//新增列標頭
   5: ListViewItem myItem;//建立ListViewItem對像
   6: //取得系統環境變數及對應的變數值,並顯示在ListView控制元件中
   7: foreach (DictionaryEntry DEntry in Environment.GetEnvironmentVariables())
   8: {
   9:     myItem = new ListViewItem(DEntry.Key.ToString(), 0);//建立ListViewItem對像
  10:     myItem.SubItems.Add(DEntry.Value.ToString());//新增子項集合
  11:     listView1.Items.Add(myItem);//將子項集合新增到控制元件中
  12: }

---------------------------------------------------------------------------------------------------------------------------

image

   1: ManagementClass mc = new ManagementClass("win32_processor"); //建立ManagementClass物件
   2: ManagementObjectCollection moc = mc.GetInstances();          //取得CPU訊息
   3: foreach (ManagementObject mo in moc)
   4: {
   5:     textBox1.Text = mo["processorid"].ToString();//取得CPU編號
   6: }
   7: ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From Win32_Processor"); //查詢CPU訊息
   8: foreach (ManagementObject mo in mos.Get() )
   9: {
  10:     textBox2.Text = mo["Manufacturer"].ToString();//取得CPU製造商名稱
  11:     textBox3.Text = mo["Version"].ToString();     //取得CPU版本號 
  12:     textBox4.Text = mo["Name"].ToString();        //取得CPU產品名稱
  13: }

---------------------------------------------------------------------------------------------------------------------------

image

   1: SelectQuery query = new SelectQuery("Select * from Win32_BaseBoard"); // 查詢主板
   2:  ManagementObjectSearcher dev = new ManagementObjectSearcher(query);   // 執行query
   3:  ManagementObjectCollection.ManagementObjectEnumerator enumerator = dev.Get().GetEnumerator();
   4:  enumerator.MoveNext();
   5:  ManagementBaseObject mbo = enumerator.Current;                    // 取得目前主板
   6:  textBox1.Text = mbo.GetPropertyValue("SerialNumber").ToString();  //取得主板編號
   7:  textBox2.Text = mbo.GetPropertyValue("Manufacturer").ToString();  //取得主板製造商
   8:  textBox3.Text = mbo.GetPropertyValue("Name").ToString();          //取得主板型號


---------------------------------------------------------------------------------------------------------------------------


資料來源: 王者歸來 599個企業專案開發完整範例集

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()