本文介绍了如何在文本框中显示总物理RAM和BIOS序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在C#中编写了一个相当基本的程序,有点像系统监视器,我们的帮助台使用它来快速从用户那里获取一些信息。 显示用户名,域名,操作系统,IP和其他一些信息。 我被要求扩展功能以包括总RAM和计算机序列号,但无论我试过什么我都不能让它显示在一个文本框。 我尝试过: RAM我尝试使用性能计数器,但这只显示可用的RAM。所以我想我需要使用WMI? 对于连续剧我有这个: I have written a fairly basic program in C#, kind of like a system monitor, which our helpdesk uses in order to quickly get some information from users. It displays Username, Domain, OS, IP and a few other bits of info. I have since been asked to extend the functionality to include total RAM and the computer serial number, but no matter what i have tried i cant get it to display in to a text box.What I have tried:For the RAM i tried using a performance counter, but this only showed available RAM. So i think i need to use WMI?For the serial i have this:public static string GetMotherBoardID() { string mbInfo = String.Empty; ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2"); scope.Connect(); ManagementObject wmiClass = new ManagementObject(scope, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions()); foreach (PropertyData propData in wmiClass.Properties) { if (propData.Name == "SerialNumber") mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value)); } return mbInfo; ITHelper.txtSerial.Text = mbInfo.ToString(); } 显示以下错误 非静态字段,方法或属性需要对象引用 对于RAM i已经尝试了 Which displays the following errorAn object reference is required for the non-static field, method, or propertyFor the RAM i have tried private static void DisplayTotalRam() { string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray"; ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query); int amount = 0; foreach (ManagementObject memo in searcher.Get()) { amount += Convert.ToInt32(Convert.ToInt64(memo["Capacity"]) / 1024 / 1024 / 1024); txtRam.Text = amount.ToString(); } } 但我得到的信息与上面相同But i get the same message as above推荐答案 0)添加对的引用Microsoft.VisualBasic 1)使用DEVICES = Microsoft.VisualBasic.Devices; 添加位于文件顶部 2)这在您的代码中: DEVICES.ComputerInfo info = new DEVICES.ComputerInfo(); 3)检查 info 用于检索所需信息的对象属性。0) Add a reference to Microsoft.VisualBasic1) Add using DEVICES=Microsoft.VisualBasic.Devices; at the top of your file2) Do this in your code: DEVICES.ComputerInfo info = new DEVICES.ComputerInfo();3) Inspect the info object properties to retrieve the desired info. 这篇关于如何在文本框中显示总物理RAM和BIOS序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 21:13