开发者

Listing WMI data in a textbox with multiple lines of input

I am trying to use WMI to gather system data which in this case I am grabbing all the startup programs and displaying them in a richtextbox. When I run the code, it works but the problem is each time it just overwrites the current text in the box and only ends up displaying the last startup item instead of all 20 startup items. Here is my code :

ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("root\\CIMV2",
                "SELECT * FROM Win32_StartupCommand");

        foreach (ManagementObject queryObj in searcher.Get())
        {

            richTextBox1.Text = "Location: {0}" + queryObj["Location"];
            richTextBox2.Text = "Location: {0}" + queryObj["Command"];
            richTextBox3.Text = "Location: {0}" + queryObj["Description"];
        }

For example, items A B and C a开发者_开发百科re told to startup. When I run my program, it will only show C in the text box because A and B were previously displayed but each time it just erases it and ends up displaying C because it's last.


you are replacing the content of the richTextBox instead of addin new lines

try this

richTextBox1.Text += string.Format("Location: {0} \n",queryObj["Location"]);
richTextBox2.Text += string.Format("Command: {0} \n",queryObj["Command"]);
richTextBox3.Text += string.Format("Description: {0} \n",queryObj["Description"]);

or

richTextBox1.AppendText(string.Format("Location: {0} \n",queryObj["Location"]));
richTextBox2.AppendText(string.Format("Command: {0} \n",queryObj["Command"]));
richTextBox3.AppendText(string.Format("Description: {0} \n",queryObj["Description"]));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜