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

  • Thread starter Thread starter M. W. Simmons
  • Start date Start date
M

M. W. Simmons

Guest
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


1381320.png

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);
}
}

Continue reading...
 
Back
Top