none
WinForm和WebForm如何读取蓝色框框里面的信息? RRS feed

答案

  • 你好,

    Webform 可以参考下面的方法:

    protected void Page_Load(object sender, EventArgs e)
            {
                SystemInfo si = new SystemInfo();       //Create an object of SystemInfo class.
                string systeminfo =  si.getOperatingSystemInfo();            
                Response.Write(systeminfo);
    
                string processinfo = si.getProcessorInfo();
    
                Response.Write(processinfo);
                GetCPUData();
            }
    
            public void GetCPUData()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
    
                String cpuName = string.Empty;
    
    
                ManagementObjectSearcher searcher = new
                    ManagementObjectSearcher("select * from Win32_Processor");
                foreach (ManagementObject o in searcher.Get())
                {
                    sb.AppendFormat("<i>{0}</i><p/>", o.ToString());
    
    
                    foreach (PropertyData prop in o.Properties)
                    {
                        sb.AppendFormat("Name: {0} Value : {1}<br/>", prop.Name, prop.Value);
                        if (prop.Name == "Name")
                            cpuName = (String)prop.Value;
                    }
                }
    
    
                sb.Insert(0, String.Format("<h3>{0}</h3>", cpuName));
    
    
                Response.Write(sb.ToString());
            }
    
        }
    
    
        public class SystemInfo
        {
            public string getOperatingSystemInfo()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendLine("Displaying operating system info....\n" + "</br>");
                //Create an object of ManagementObjectSearcher class and pass query as parameter.
                ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
    
                string temp = string.Empty;
                foreach (ManagementObject managementObject in mos.Get())
                {
                    foreach (PropertyData prop in managementObject.Properties)
                    {
                        sb.AppendFormat("Name: {0} Value : {1}<br/>", prop.Name, prop.Value);
                        if (prop.Name == "Name")
                            temp = (String)prop.Value;
                    }
    
                    //if (managementObject["Caption"] != null)
                    //{
                    //    sb.AppendLine("Operating System Name  :  " + managementObject["Caption"].ToString() + "</br>");   //Display operating system caption
                    //}
                    //if (managementObject["OSArchitecture"] != null)
                    //{
                    //    sb.AppendLine("Operating System Architecture  :  " + managementObject["OSArchitecture"].ToString() + "</br>");   //Display operating system architecture.
                    //}
                    //if (managementObject["CSDVersion"] != null)
                    //{
                    //    sb.AppendLine("Operating System Service Pack   :  " + managementObject["CSDVersion"].ToString() + "</br>");     //Display operating system version.
                    //}
                }
    
                return sb.ToString();
    
            }
    
            public string getProcessorInfo()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                Console.WriteLine("\n\nDisplaying Processor Name....");
                RegistryKey processor_name = Registry.LocalMachine.OpenSubKey(@"Hardware\Description\System\CentralProcessor\0", RegistryKeyPermissionCheck.ReadSubTree);   //This registry entry contains entry for processor info.
    
                if (processor_name != null)
                {
                    if (processor_name.GetValue("ProcessorNameString") != null)
                    {
                        sb.AppendLine(processor_name.GetValue("ProcessorNameString").ToString() +"</br>");   //Display processor ingo.
                    }
                }
    
                return sb.ToString();
            }
        }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 Lexan-Live 2018年12月6日 6:26
    2018年12月5日 8:16
    版主

全部回复

  • 你好,

    什么是蓝色框框,可以详细的描述一下吗?

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年12月5日 6:26
    版主
  • 就是图片中的用蓝色框起来的信息,就是进入运行cmd程序输入systeminfo,就控制台里面的,用C#怎么去获取OS版本,还有获取修补程序列表
    2018年12月5日 6:36
  • 你好,

    Webform 可以参考下面的方法:

    protected void Page_Load(object sender, EventArgs e)
            {
                SystemInfo si = new SystemInfo();       //Create an object of SystemInfo class.
                string systeminfo =  si.getOperatingSystemInfo();            
                Response.Write(systeminfo);
    
                string processinfo = si.getProcessorInfo();
    
                Response.Write(processinfo);
                GetCPUData();
            }
    
            public void GetCPUData()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
    
                String cpuName = string.Empty;
    
    
                ManagementObjectSearcher searcher = new
                    ManagementObjectSearcher("select * from Win32_Processor");
                foreach (ManagementObject o in searcher.Get())
                {
                    sb.AppendFormat("<i>{0}</i><p/>", o.ToString());
    
    
                    foreach (PropertyData prop in o.Properties)
                    {
                        sb.AppendFormat("Name: {0} Value : {1}<br/>", prop.Name, prop.Value);
                        if (prop.Name == "Name")
                            cpuName = (String)prop.Value;
                    }
                }
    
    
                sb.Insert(0, String.Format("<h3>{0}</h3>", cpuName));
    
    
                Response.Write(sb.ToString());
            }
    
        }
    
    
        public class SystemInfo
        {
            public string getOperatingSystemInfo()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendLine("Displaying operating system info....\n" + "</br>");
                //Create an object of ManagementObjectSearcher class and pass query as parameter.
                ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
    
                string temp = string.Empty;
                foreach (ManagementObject managementObject in mos.Get())
                {
                    foreach (PropertyData prop in managementObject.Properties)
                    {
                        sb.AppendFormat("Name: {0} Value : {1}<br/>", prop.Name, prop.Value);
                        if (prop.Name == "Name")
                            temp = (String)prop.Value;
                    }
    
                    //if (managementObject["Caption"] != null)
                    //{
                    //    sb.AppendLine("Operating System Name  :  " + managementObject["Caption"].ToString() + "</br>");   //Display operating system caption
                    //}
                    //if (managementObject["OSArchitecture"] != null)
                    //{
                    //    sb.AppendLine("Operating System Architecture  :  " + managementObject["OSArchitecture"].ToString() + "</br>");   //Display operating system architecture.
                    //}
                    //if (managementObject["CSDVersion"] != null)
                    //{
                    //    sb.AppendLine("Operating System Service Pack   :  " + managementObject["CSDVersion"].ToString() + "</br>");     //Display operating system version.
                    //}
                }
    
                return sb.ToString();
    
            }
    
            public string getProcessorInfo()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                Console.WriteLine("\n\nDisplaying Processor Name....");
                RegistryKey processor_name = Registry.LocalMachine.OpenSubKey(@"Hardware\Description\System\CentralProcessor\0", RegistryKeyPermissionCheck.ReadSubTree);   //This registry entry contains entry for processor info.
    
                if (processor_name != null)
                {
                    if (processor_name.GetValue("ProcessorNameString") != null)
                    {
                        sb.AppendLine(processor_name.GetValue("ProcessorNameString").ToString() +"</br>");   //Display processor ingo.
                    }
                }
    
                return sb.ToString();
            }
        }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 Lexan-Live 2018年12月6日 6:26
    2018年12月5日 8:16
    版主