-1
  public ManagementScope GetScope()
    {
        try
        {
            //string classScope="winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\\root\\cimv2";
            string serverString = @"root\cimv2";

            ManagementScope scope = new ManagementScope(serverString);


                ConnectionOptions options = new ConnectionOptions
                {
                    Impersonation = ImpersonationLevel.Impersonate,
                    Authentication = AuthenticationLevel.Connect,
                    EnablePrivileges = true
                };
                scope.Options = options; 

            return scope; 
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw;
        }
    }

    public void InvokeMethodsFunctions1()
    {
        ManagementScope mScope = GetScope();

        mScope.Connect();

        if (mScope.IsConnected)
        {
            ManagementClass processClass =
                new ManagementClass(mScope.Path);
            ManagementObjectSearcher mos = new ManagementObjectSearcher(mScope, new ObjectQuery("SELECT * FROM Win32_Product"));
            //get collection of WMI objects
            ManagementObjectCollection queryCollection = mos.Get();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Result.txt"))
            {
                textBox1.Text = "";
                //enumerate the collection.
                foreach (ManagementObject m in queryCollection)
                {
                    // access properties of the WMI object
                    string line = " " + m["Name"] + " , InstallDate : " + m["InstallDate"] + " LocalPackage : " + m["LocalPackage"];
                    Console.WriteLine(line);
                    file.WriteLine(line);
                    textBox1.Text += line + "\n";
                }
            }

       }

    }

So whats wrong in my Code ?

Khaleel Hmoz
  • 987
  • 2
  • 13
  • 24

2 Answers2

2

There is nothing wrong , the Win32_Product WMI class only list the products installed by the Windows Installer (MSI).

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Yes this is my problem, is there a way i can list also products that not installed by (MSI) – Khaleel Hmoz Oct 31 '13 at 07:50
  • @KhaleelHmoz: Yes, from the registry. See this question: [Get installed applications in a system](http://stackoverflow.com/q/908850/113116). – Helen Nov 01 '13 at 08:42
  • I'm Having a Problem with the Registry values i need to search about, I'm trying to Monitor Some software if they installed , but lately these software had made the displayname values localized and im trying to find values not localized in the registry, there is no such values. so i tried to get the other way which is WMI hoping that the values I get will be in English. the first problem now is i need to get all installed softwares even not from MSI... : ( – Khaleel Hmoz Nov 03 '13 at 09:28
1

I just tested the following, simplified version of your code and I see everything installed on my pc, even services I wrote and installed myself:

var products = new ManagementObjectSearcher(new ObjectQuery("SELECT * FROM Win32_Product"));
var result = products.Get();

foreach (var product in result)
{
    Console.WriteLine(product.GetPropertyValue("Name").ToString());
}

Console.ReadLine();

It looks like you are narrowing your query by scope, which is possibly why you aren't seeing everything, try the above and see if you have more luck.

JMK
  • 27,273
  • 52
  • 163
  • 280
  • I'm trying to get names of software not installed by MSI, thats why there is some softwares dosn't appear, because they installed from their own installer – Khaleel Hmoz Nov 03 '13 at 09:33