Windows Forms - How to return WMIC output into Textbox

僤鯓⒐⒋嵵緔 提交于 2019-12-25 14:22:37

问题


I'm new to coding (3 days in and learning primarily from Google) it's going well enough so far but now I'm stuck :)

I want to run a WMIC command and return the second line of the output into a textbox. The WMIC command is:

'WMIC bios get serialnumber'

This returns:

SerialNumber 
 ABCD1234

How do I get just the serial number into a textbox please?

Thanks...


回答1:


Add reference to System.Management and use the following in your form method.

        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
        ManagementObject obj = searcher.Get().Cast<ManagementObject>().FirstOrDefault();          

            textBox.Text =  (string)obj["SerialNumber"];


来源:https://stackoverflow.com/questions/32436424/windows-forms-how-to-return-wmic-output-into-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!