WMI not responds

  • Thread starter Alhambra Eidos Desarrollo
  • Start date
A

Alhambra Eidos Desarrollo

Hi mister,

I need use WMI for get list of applications installed.
This is my code:

ManagementObjectSearcher query = null;
ManagementObjectCollection queryAPPSCollection = null;
//ManagementScope msc = new ManagementScope("\\" + computer_name
+ @"\root\cimv2");
ManagementScope msc = new ManagementScope("root\\CIMV2");
string query_command = "SELECT * FROM Win32_Product";
SelectQuery select_query = new SelectQuery(query_command);
query = new ManagementObjectSearcher(msc, select_query);
queryAPPSCollection = query.Get();


foreach (ManagementObject mo in queryAPPSCollection)
{

when it executes foreach the application not responds !!!

Any solution about it ?? please...regards...
 
T

Tim Jarvis

Alhambra said:
Hi mister,

I need use WMI for get list of applications installed.
This is my code:

ManagementObjectSearcher query = null;
ManagementObjectCollection queryAPPSCollection = null;
//ManagementScope msc = new ManagementScope("\\" +
computer_name + @"\root\cimv2");
ManagementScope msc = new ManagementScope("root\\CIMV2");
string query_command = "SELECT * FROM Win32_Product";
SelectQuery select_query = new SelectQuery(query_command);
query = new ManagementObjectSearcher(msc, select_query);
queryAPPSCollection = query.Get();


foreach (ManagementObject mo in queryAPPSCollection)
{

when it executes foreach the application not responds !!!

Any solution about it ?? please...regards...

Hi Alhambra,

Getting the installed apps takes a long time (on my fast machine with
only a moderate amount of apps installed about 120 seconds or so) I
think that probably you are not hung, just waiting a long time.


Here is a Powershell version of the same thing, again, it takes ages on
my machine and does appear hung for a couple minutes.

Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();
Pipeline pl = rs.CreatePipeline();
pl.Commands.AddScript("get-wmiobject win32_Product");

StringBuilder sb = new StringBuilder();
Collection<PSObject> list = pl.Invoke();
rs.Close();
foreach (PSObject obj in list)
{
var app = new
{
Name = obj.Properties["Name"].Value as string,
Vendor = obj.Properties["Vendor"].Value as string,
Version = obj.Properties["Version"].Value,
Caption = obj.Properties["Caption"].Value as string
};
sb.AppendLine(string.Format("{0,-200}{1}",app.Name, app.Version !=
null ? app.Version.ToString() : "[null]"));
}
textBox1.Text = sb.ToString();

Regards Tim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top