2012-07-20 60 views
1

如何查看邏輯內存配置?C#邏輯內存配置視圖

private void button1_Click(object sender, EventArgs e) 
    { 
     ObjectQuery winQuery = new ObjectQuery("SELECT * FROM Win32_LogicalMemoryConfiguration"); 
     ManagementObjectSearcher searcher = new ManagementObjectSearcher(winQuery); 
     foreach (ManagementObject item in searcher.Get()) 
     { 
      textBox1.Text =("Total Space = " + item["TotalPageFileSpace"]); 
      textBox2.Text = ("Total Physical Memory = " + item["TotalPhysicalMemory"]); 
      textBox3.Text = ("Total Virtual Memory = " + item["TotalVirtualMemory"]); 
      textBox4.Text = ("Available Virtual Memory = " + item["AvailableVirtualMemory"]); 
     } 
    } 

在這段代碼似乎不起作用。並且在編譯時沒有錯誤。

+2

運行它時會顯示什麼? – danish 2012-07-20 11:58:44

+0

什麼都沒有!毫無例外 ! – deleted 2012-07-20 12:00:58

回答

4

根據Microsoft

的Win32_LogicalMemoryConfiguration WMI類不再可供用作Windows Vista中的。

該文章建議您使用Win32_OperatingSystem,但您最好使用Process.GetCurrentProcess()

+0

哦,不!謝謝 ! – deleted 2012-07-20 12:08:25