none
Query SCCM 2012 from C# to get applications installed/notinstalled remotely from SCCM Client with WMI RRS feed

  • Question

  • Hi All

     

    I am asking for help to gather information from the "SELECT * FROM CCM_Application" -namespace "ROOT\ccm\ClientSDK"

    and display its information into a DataGrid.
    The problem is the data I am getting is not complete and the objects I could actually get the data from is in the DeploymentReport Object it seems.

    I need information such as Name,InstallState,EvaluationState

    the same query in powershell pulls this information but I am unable to get it from C# correctly.


    __GENUS                    : 2
    __CLASS                    : CCM_Application
    __SUPERCLASS               : CCM_SoftwareBase
    __DYNASTY                  : CCM_SoftwareBase
    __RELPATH                  : CCM_Application.Id="ScopeId_076322AE-B017-4E62-B3AD-A4FDB580BD1C/Application_faf6010d-6815-4dbc-bd61-c719f9773768",IsMachineTarget=TRUE,Revision="8"
    __PROPERTY_COUNT           : 38
    __DERIVATION               : {CCM_SoftwareBase}
    __SERVER                   : MYCOMPUTERNAMEHERE
    __NAMESPACE                : root\ccm\clientsdk
    __PATH                     : \\MYCOMPUTERNAMEHERE\root\ccm\clientsdk:CCM_Application.Id="ScopeId_076322AE-B017-4E62-B3AD-A4FDB580BD1C/Application_faf6010d-6815-4dbc-bd61-c719f9773768",IsMachineTarget=TRUE,Revision="8"
    AllowedActions             : {Install}
    AppDTs                     :
    ApplicabilityState         : Applicable
    ConfigureState             : NotNeeded
    ContentSize                :
    Deadline                   : 20180426132700.000000+000
    DeploymentReport           :
    Description                :
    EnforcePreference          : 2
    ErrorCode                  : 0
    EstimatedInstallTime       :
    EvaluationState            : 1
    FileTypes                  :
    FullName                   : Passport Web to Host Patch 21.1.2.307
    Icon                       :
    Id                         : ScopeId_076322AE-B017-4E62-B3AD-A4FDB580BD1C/Application_faf6010d-6815-4dbc-bd61-c719f9773768
    InformativeUrl             :
    InProgressActions          : {}
    InstallState               : Installed
    IsMachineTarget            : True
    IsPreflightOnly            : False
    LastEvalTime               : 20190109091731.000000+000
    LastInstallTime            : 20181009174722.000000+000
    Name                       : Passport Web to Host Patch 21.1.2.307
    NextUserScheduledTime      :
    NotifyUser                 : False
    OverrideServiceWindow      : False
    PercentComplete            : 0
    Publisher                  : Rocket Software
    RebootOutsideServiceWindow : False
    ReleaseDate                : 00000000000000.000000+000
    ResolvedState              : Installed
    Revision                   : 8
    SoftwareVersion            : 21.1.2.307
    StartTime                  : 20180426132700.000000+000
    SupersessionState          : None
    Type                       : 1
    UserUIExperience           : True
    PSComputerName             : MYCOMPUTERNAMEHERE


    

    my code is 
            public CCMView(string targetComputer)
            {
                InitializeComponent();
                // Display loading animations.
                //gridError.Visibility = Visibility.Collapsed;
              //  gridLoading.Visibility = Visibility.Visible;
                new Thread(() => RefreshProcessesList()) { IsBackground = true }.Start();
    
            }
    
    
            private void RefreshProcessesList()
            {
                try
                {
                    ManagementScope scope = new ManagementScope(@"\\" + GlobalVar.TargetComputerName + @"\ROOT\ccm\ClientSDK:CCM_SoftwareBase");
                    SelectQuery query = new SelectQuery("Select * From CCM_SoftwareBase");
                     var typeDescriptors = new ObservableCollection<ManagementObjectTypeDescriptor>();
    
                    using (var searcher = new ManagementObjectSearcher(scope, query))
                    {
                        using (var managementObjects = searcher.Get())
                        {
                            foreach (ManagementBaseObject managementObject in managementObjects)
                            {
                                using (managementObject)
                                {
                                    typeDescriptors.Add(new ManagementObjectTypeDescriptor(managementObject));
                                }
                            }
                        }
                    }
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                    CcmAppsGrid.ItemsSource = new ArrayList(typeDescriptors);
                        gridError.Visibility = Visibility.Collapsed;
                        gridLoading.Visibility = Visibility.Collapsed;
                        CcmAppsGrid.Items.SortDescriptions.Clear();
                        CcmAppsGrid.Items.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
    
                    }));
    
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message);
                }
            }

    • Edited by M. W. Simmons Tuesday, January 15, 2019 11:29 PM add code
    Tuesday, January 15, 2019 11:26 PM

All replies

  • Hi M. W. Simmons,

    Thank you for posting here.

    We are installing the SCCM2012 environment , please wait patiently.

    We could deal with your problem in time.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 18, 2019 9:22 AM
    Moderator
  • ok thanks
    Tuesday, January 22, 2019 3:50 PM
  • Hi M.W.Simmons,

    Based on your description, you want to get information about the query correctly by using c#.

    I suggest that you could call powershell from c#, you also could get the information aboout the query.

    The following link is a example for calling powershell from c#.

    https://stackoverflow.com/questions/13251076/calling-powershell-from-c-sharp

    Hope my advice could be helpful.

    Best Regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 31, 2019 9:41 AM
    Moderator