public List<string> WMIGetInstalledSoftware(string pcname)
{
string query = "select Name from win32_product";
pcname = CleanPCName(pcname);
StringBuilder queryResult = new StringBuilder();
List<string> resultList = new List<string>();
try
{
ManagementScope scope = new ManagementScope(backslashes + pcname + @"\root\cimv2");
scope.Connect();
ObjectQuery obquery = new ObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, obquery);
foreach (ManagementObject obj in searcher.Get())
{
try
{
resultList.Add(obj["Name"].ToString());
}
catch
{
resultList.Add("Unknown");
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
resultList.Sort();
return resultList;
}
public List<string> WMIGetHotfixes(string pcname)
{
string query = "select HotFixID from Win32_QuickFixEngineering";
pcname = CleanPCName(pcname);
StringBuilder queryResult = new StringBuilder();
List<string> resultList = new List<string>();
try
{
ManagementScope scope = new ManagementScope(backslashes + pcname + @"\root\cimv2");
scope.Connect();
ObjectQuery obquery = new ObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, obquery);
foreach (ManagementObject obj in searcher.Get())
{
try
{
if (!obj["HotFixID"].Equals(null))
{
if (!obj["HotFixID"].ToString().Contains("File 1"))
{
resultList.Add(obj["HotFixID"].ToString());
}
}
}
catch
{
resultList.Add("Unknown");
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
resultList.Sort();
return resultList;
}
Thursday, October 15, 2015
Getting Installed software and hotfixes remotely in .NET with WMI
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment