Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wmi CIM_DataFile

Status
Not open for further replies.

bouwob

Programmer
Apr 12, 2006
171
0
0
US
I have this bit of code

Code:
                int counter = 0;
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\\" + strComputerName + @"\root\CIMV2", "SELECT * FROM CIM_DataFile where Extension = 'exe'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    this.txtMessageBox.Text = this.txtMessageBox.Text + counter.ToString() + "CIM_DataFile instance" + " ";
                    this.txtMessageBox.Text = this.txtMessageBox.Text + "CreationDate:" + queryObj["CreationDate"].ToString() + " ";
                    this.txtMessageBox.Text = this.txtMessageBox.Text + "Caption:" + queryObj["Caption"].ToString() + " ";
                    this.txtMessageBox.Text = this.txtMessageBox.Text + "CSName:" + queryObj["CSName"].ToString() + " ";
                    this.txtMessageBox.Text = this.txtMessageBox.Text + "FileName:" + queryObj["FileName"].ToString() + " ";
                    try
                    {
                        this.txtMessageBox.Text = this.txtMessageBox.Text + "Manufacturer:" + queryObj["Manufacturer"].ToString() + " ";
                    }
                    catch
                    {
                        this.txtMessageBox.Text = this.txtMessageBox.Text + "Manufacturer:NULL ";
                    }
                    this.txtMessageBox.Text = this.txtMessageBox.Text + "LastAccessed:" + queryObj["LastAccessed"].ToString() + "\r\n";
                    counter++;
               
                }

The problem I am having though is that it takes for ever to run. Assuming I have 3000 executables I believe this code will hit the remote machine 3000 different times to get 1 set of information and then moving on to the next.

So my question is, how do I grab all of the data at once and then iterate through the list on my own box? I want to connect once, grab the info and display the results using as little network as possable.

tia
 
what's a ManagementObjectSearcher?

what does ManagementObjectSearcher.Get() return?

it should return an object that exposes IEnumerable.

in which case "foreach ( T x in c )" should make the call just once.

i have a feeling what's slow is your concatenating strings. use a StringBuilder object instead, and/or override the ManagementObject.ToString() method to tidy away all the string assignment.

the try block around queryObj["Manufacturer"].ToString() is unnecessary, use the ?? operator:

(queryObj["Manufacturer"] ?? "NULL").ToString()

HTH,


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top