public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoHardDriveInventory>(new DtoHardDriveInventory())) { collection.HardDrives = wmi.GetObjectList(); } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoBiosInventory>(new DtoBiosInventory())) { collection.Bios = wmi.Execute(); } }
public bool Run() { Logger.Info("Running Inventory Module"); var collection = new DtoInventoryCollection(); var instances = from t in Assembly.GetExecutingAssembly().GetTypes() where t.GetInterfaces().Contains(typeof(IInventorySearcher)) && t.GetConstructor(Type.EmptyTypes) != null select Activator.CreateInstance(t) as IInventorySearcher; foreach (var instance in instances) { Logger.Debug("Scanning " + instance); instance.Search(collection); } var result = new APICall().InventoryApi.SubmitInventory(collection); if (result != null) { return(result.Value); } else { return(false); } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoBitlockerInventory>(new DtoBitlockerInventory(), "root\\cimv2\\security\\microsoftvolumeencryption")) { collection.Bitlocker = wmi.GetObjectList(); } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoProcessorInventory>(new DtoProcessorInventory())) { collection.Processor = wmi.Execute(); } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoPrinterInventory>(new DtoPrinterInventory())) { collection.Printers = wmi.GetObjectList(); } //Per computer printers aren't included in wmi when ran as the system account //add them via registry var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Connections"); if (key == null) { return; } foreach (var subKey in key.GetSubKeyNames()) { var printerConnection = key.OpenSubKey(subKey); if (printerConnection == null) { continue; } var printerPath = Convert.ToString(printerConnection.GetValue("Printer")); var printerName = printerPath.Split('\\').Last(); var server = Convert.ToString(printerConnection.GetValue("Server")); collection.Printers.Add(new DtoPrinterInventory { SystemName = server, Name = printerPath, ShareName = printerName }); } //collection.Printers = collection.Printers.GroupBy(x => new {x.Name, x.DriverName}).Select(g => g.First()).ToList(); }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoComputerSystemInventory>(new DtoComputerSystemInventory())) { collection.ComputerSystem = wmi.Execute(); } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoLogicalVolumeWmi>(new DtoLogicalVolumeWmi())) { var volumes = wmi.GetObjectList(); foreach (var volume in volumes) { var lvInventory = new DtoLogicalVolumeInventory(); try { string free = (volume.FreeSpace / 1024 / 1024 / 1024).ToString(); string size = (volume.Size / 1024 / 1024 / 1024).ToString(); var freePercent = Math.Round((Convert.ToDouble(free) / Convert.ToDouble(size) * 100)); lvInventory.Drive = volume.DeviceId; lvInventory.FreeSpacePercent = Convert.ToInt32(freePercent); lvInventory.FreeSpaceGB = Convert.ToInt32(free); lvInventory.SizeGB = Convert.ToInt32(size); collection.LogicalVolume.Add(lvInventory); } catch { //ignored } } } }
public DtoBoolResponse SubmitInventory(DtoInventoryCollection collection) { Request.Method = Method.POST; Request.Timeout = 900000; Request.Resource = string.Format("ProvisionedComm/{0}/SubmitInventory/", Resource); return(new ApiRequest(900000).ExecuteSymKeyEncryption <DtoBoolResponse>(Request, JsonConvert.SerializeObject(collection))); }
public DtoApiBoolResponse SubmitInventory(DtoInventoryCollection collection) { var clientId = RequestContext.Principal.Identity.Name; var result = new SubmitInventory().Run(collection, clientId); return(new DtoApiBoolResponse() { Value = result }); }
public void Search(DtoInventoryCollection collection) { //http://csharphelper.com/blog/2015/01/access-firewall-information-and-check-firewall-status-using-the-dynamic-keyword-in-c/ Type FWManagerType = Type.GetTypeFromProgID("HNetCfg.FwPolicy2"); dynamic FWManager = Activator.CreateInstance(FWManagerType); collection.Firewall.DomainEnabled = FWManager.FirewallEnabled(NET_FW_PROFILE2_DOMAIN); collection.Firewall.PrivateEnabled = FWManager.FirewallEnabled(NET_FW_PROFILE2_PRIVATE); collection.Firewall.PublicEnabled = FWManager.FirewallEnabled(NET_FW_PROFILE2_PUBLIC); }
public void Search(DtoInventoryCollection collection) { var userkey = Registry.Users; if (userkey == null) { return; } foreach (var subKey in userkey.GetSubKeyNames()) { var userUninstallKey = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64); userUninstallKey = userUninstallKey.OpenSubKey(string.Format( @"{0}\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", subKey)); if (userUninstallKey == null) { continue; } AddToCollection(userUninstallKey); userUninstallKey = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry32); userUninstallKey = userUninstallKey.OpenSubKey(string.Format( @"{0}\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", subKey)); if (userUninstallKey == null) { continue; } AddToCollection(userUninstallKey); } var machineUninstallKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); machineUninstallKey = machineUninstallKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (machineUninstallKey == null) { return; } AddToCollection(machineUninstallKey); machineUninstallKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); machineUninstallKey = machineUninstallKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (machineUninstallKey == null) { return; } AddToCollection(machineUninstallKey); collection.Software = _softwareIventory.Distinct(new SoftwareComparer()).ToList(); }
public bool Run(DtoInventoryCollection collection, string clientIdentifier) { var client = new ServiceComputer().GetByGuid(clientIdentifier); if (client == null) { return(false); } new ServiceBiosInventory().AddOrUpdate(collection.Bios, client.Id); new ServiceComputerSystemInventory().AddOrUpdate(collection.ComputerSystem, client.Id); new ServiceOsInventory().AddOrUpdate(collection.Os, client.Id); new ServiceProcessorInventory().AddOrUpdate(collection.Processor, client.Id); new ServicePrinterInventory().AddOrUpdate(collection.Printers, client.Id); new ServiceHardDriveInventory().AddOrUpdate(collection.HardDrives, client.Id); new ServiceNicInventory().AddOrUpdate(collection.NetworkAdapters, client.Id); new ServiceWuInventory().Add(collection.WindowsUpdates); new ServiceComputerUpdates().AddOrUpdate(collection.WindowsUpdates, client.Id); new ServiceSoftwareInventory().Add(collection.Software); new ServiceComputerSoftware().AddOrUpdate(collection.Software, client.Id); new ServiceCertificateInventory().Add(collection.Certificates); new ServiceComputerCertificate().AddOrUpdate(collection.Certificates, client.Id); new ServiceAntivirusInventory().AddOrUpdate(collection.AntiVirus, client.Id); new ServiceLogicalVolumeInventory().AddOrUpdate(collection.LogicalVolume, client.Id); new ServiceBitlockerInventory().AddOrUpdate(collection.Bitlocker, client.Id); new ServiceFirewallInventory().AddOrUpdate(collection.Firewall, client.Id); client.LastInventoryTime = DateTime.Now; if (!string.IsNullOrEmpty(collection.ClientVersion)) { client.ClientVersion = collection.ClientVersion; } if (!string.IsNullOrEmpty(collection.PushUrl)) { client.PushUrl = collection.PushUrl; } if (!string.IsNullOrEmpty(collection.HardwareUUID)) { client.UUID = collection.HardwareUUID; } new ServiceComputer().UpdateComputer(client); new ServiceImagingClientId().AddOrUpdate(client.Id); return(true); }
public DtoInventoryCollection GetSystemInfo(int computerId) { var systemInfo = new DtoInventoryCollection(); systemInfo.Bios = _uow.BiosInventoryRepository.Get(x => x.ComputerId == computerId).FirstOrDefault(); systemInfo.ComputerSystem = _uow.ComputerSystemInventoryRepository.Get(x => x.ComputerId == computerId).FirstOrDefault(); systemInfo.Os = _uow.OsInventoryRepository.Get(x => x.ComputerId == computerId).FirstOrDefault(); systemInfo.Processor = _uow.ProcessorInventoryRepository.Get(x => x.ComputerId == computerId).FirstOrDefault(); systemInfo.HardDrives = _uow.HardDriveInventoryRepository.Get(x => x.ComputerId == computerId); systemInfo.Printers = _uow.PrinterInventoryRepository.Get(x => x.ComputerId == computerId); systemInfo.Nics = _uow.NicInventoryRepository.Get(x => x.ComputerId == computerId); systemInfo.AntiVirus = _uow.AntivirusRepository.Get(x => x.ComputerId == computerId); systemInfo.Bitlocker = _uow.BitlockerRepository.Get(x => x.ComputerId == computerId); systemInfo.Firewall = _uow.FirewallRepository.Get(x => x.ComputerId == computerId).FirstOrDefault(); systemInfo.LogicalVolume = _uow.LogicalVolumeRepository.Get(x => x.ComputerId == computerId); return(systemInfo); }
public void Search(DtoInventoryCollection collection) { foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) { try { var nic = new DtoNicInventory(); nic.Name = adapter.Name; nic.Description = adapter.Description; nic.Type = adapter.NetworkInterfaceType.ToString(); nic.Mac = adapter.GetPhysicalAddress().ToString(); nic.Status = adapter.OperationalStatus.ToString(); nic.Speed = adapter.Speed; nic.Ips = string.Empty; nic.Gateways = string.Empty; foreach ( var ip in adapter.GetIPProperties() .UnicastAddresses.Where(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork)) { nic.Ips += ip.Address + ","; } nic.Ips = nic.Ips.Trim(','); foreach ( var gateway in adapter.GetIPProperties() .GatewayAddresses.Where(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork)) { nic.Gateways += gateway.Address + ","; } nic.Gateways = nic.Gateways.Trim(','); collection.NetworkAdapters.Add(nic); } catch { //Ignore } } }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoComputerSystemInventory>(new DtoComputerSystemInventory())) { collection.ComputerSystem = wmi.Execute(); } using (var wmi = new ServiceWmi <DtoComputerSystemProduct>(new DtoComputerSystemProduct())) { var computerSystemProduct = wmi.Execute(); if (computerSystemProduct != null) { collection.HardwareUUID = computerSystemProduct.UUID; } else { collection.HardwareUUID = string.Empty; } } }
public void Search(DtoInventoryCollection collection) { foreach (var s in (StoreName[])Enum.GetValues(typeof(StoreName))) { if (s != StoreName.My && s != StoreName.Root && s != StoreName.CertificateAuthority) { continue; } var store = new X509Store(s, StoreLocation.LocalMachine); try { store.Open(OpenFlags.ReadOnly); var certs = store.Certificates; foreach (var cert in certs) { var certItem = new DtoCertificateInventory(); certItem.Store = s.ToString(); certItem.Subject = cert.Subject; certItem.FriendlyName = cert.FriendlyName; certItem.Thumbprint = cert.Thumbprint; certItem.Serial = cert.SerialNumber; certItem.Issuer = cert.Issuer; certItem.NotBefore = cert.NotBefore; certItem.NotAfter = cert.NotAfter; collection.Certificates.Add(certItem); } } catch (Exception ex) { Logger.Error($"Could Not Get Certificate Inventory For {s.ToString()} Store"); Logger.Error(ex.Message); } finally { store.Close(); } } }
public void Search(DtoInventoryCollection collection) { var updateSession = new UpdateSession(); var updateSearchResult = updateSession.CreateUpdateSearcher(); updateSearchResult.Online = true; updateSearchResult.ServerSelection = ServerSelection.ssWindowsUpdate; updateSearchResult.IncludePotentiallySupersededUpdates = false; try { var searchResults = updateSearchResult.Search("IsInstalled=0 and Type='Software'"); foreach (IUpdate u in searchResults.Updates) { var update = new DtoWindowsUpdateInventory { IsInstalled = false }; update.Title = u.Title; update.UpdateId = u.Identity.UpdateID; foreach (ICategory ic in u.Categories) { update.Category = ic.Name; break; } if (!string.IsNullOrEmpty(update.Title)) { collection.WindowsUpdates.Add(update); } } } catch { //Ignored } }
private EnumProvisionStatus.Status ProvisionStage2() { var intermediateThumbprint = _serviceSetting.GetSetting("intermediate_thumbprint"); if (string.IsNullOrEmpty(intermediateThumbprint.Value)) { //assume stage 1 didn't finish return(EnumProvisionStatus.Status.NotStarted); } var intermediate = ServiceCertificate.GetCertificateFromStore(intermediateThumbprint.Value, StoreName.CertificateAuthority); if (intermediate == null) { return(EnumProvisionStatus.Status.NotStarted); } var key = GenerateSymmKey(); var provisionRequest = new DtoProvisionRequest(); provisionRequest.Name = DtoGobalSettings.ClientIdentity.Name; provisionRequest.AdGuid = new ServiceAD().GetADGuid(provisionRequest.Name); provisionRequest.SymmKey = EncryptDataWithIntermediate(intermediate.PublicKey.Key, key); provisionRequest.InstallationId = DtoGobalSettings.ClientIdentity.InstallationId; //include some hardware details Logger.Debug("Gathering Hardware Details"); var inventoryCollection = new DtoInventoryCollection(); new ComputerSystem().Search(inventoryCollection); new Bios().Search(inventoryCollection); new Processor().Search(inventoryCollection); new Nic().Search(inventoryCollection); try { var m = Convert.ToInt64(inventoryCollection.ComputerSystem.TotalPhysicalMemory); provisionRequest.Memory = Convert.ToInt32(m / 1024 / 1024); } catch { provisionRequest.Memory = 0; } try { provisionRequest.Processor = inventoryCollection.Processor.Name; } catch { provisionRequest.Processor = string.Empty; } try { provisionRequest.SerialNumber = inventoryCollection.Bios.SerialNumber; } catch { provisionRequest.SerialNumber = string.Empty; } try { provisionRequest.Model = inventoryCollection.ComputerSystem.Model; } catch { provisionRequest.Model = string.Empty; } try { foreach (var nic in inventoryCollection.NetworkAdapters) { provisionRequest.Macs.Add(nic.Mac); } } catch { //do nothing } inventoryCollection = null; var response = new APICall().ProvisionApi.ProvisionClient(provisionRequest); if (response == null) { return(EnumProvisionStatus.Status.Error); } if (response.ProvisionStatus == EnumProvisionStatus.Status.Reset) { Logger.Info("Client Reset Approved. Starting Reset Process."); return(EnumProvisionStatus.Status.Reset); } if (response.ProvisionStatus == EnumProvisionStatus.Status.FullReset) { Logger.Info("Client Full Reset Requested. Starting Full Reset Process."); return(EnumProvisionStatus.Status.FullReset); } if (response.ProvisionStatus == EnumProvisionStatus.Status.PendingReset) { Logger.Info("Client Is Pending Reset Approval."); return(EnumProvisionStatus.Status.PendingReset); } if (response.ProvisionStatus == EnumProvisionStatus.Status.PendingProvisionApproval) { Logger.Info("Client Is Pending Provisioning Approval"); return(EnumProvisionStatus.Status.PendingProvisionApproval); } if (response.ProvisionStatus == EnumProvisionStatus.Status.PendingPreProvision) { Logger.Info("Client Has Not Been Pre-Provisioned And The Current Security Policy Requires It."); return(EnumProvisionStatus.Status.PendingPreProvision); } if (response.ProvisionStatus != EnumProvisionStatus.Status.PendingConfirmation) { return(EnumProvisionStatus.Status.Error); } var byteCert = Convert.FromBase64String(response.Certificate); var base64Cert = new ServiceSymmetricEncryption().Decrypt(key, byteCert); var deviceCert = new X509Certificate2(Convert.FromBase64String(base64Cert)); if (ServiceCertificate.StoreLocalMachine(deviceCert, StoreName.My)) { var deviceThumbprint = _serviceSetting.GetSetting("device_thumbprint"); deviceThumbprint.Value = deviceCert.Thumbprint; _serviceSetting.UpdateSettingValue(deviceThumbprint); var computerIdentifier = _serviceSetting.GetSetting("computer_identifier"); computerIdentifier.Value = response.ComputerIdentifier; DtoGobalSettings.ClientIdentity.Guid = response.ComputerIdentifier; _serviceSetting.UpdateSettingValue(computerIdentifier); var entropy = _serviceSetting.GetSetting("entropy"); var entropyBytes = ServiceDP.CreateRandomEntropy(); entropy.Value = Convert.ToBase64String(entropyBytes); _serviceSetting.UpdateSettingValue(entropy); var encryptedKey = ServiceDP.EncryptData(key, true, entropyBytes); var keySetting = _serviceSetting.GetSetting("encryption_key"); keySetting.Value = Convert.ToBase64String(encryptedKey); _serviceSetting.UpdateSettingValue(keySetting); var settingProvisionStatus = _serviceSetting.GetSetting("provision_status"); settingProvisionStatus.Value = Convert.ToInt16(response.ProvisionStatus).ToString(); _serviceSetting.UpdateSettingValue(settingProvisionStatus); } return(EnumProvisionStatus.Status.PendingConfirmation); }
public void Search(DtoInventoryCollection collection) { List <DtoAntiVirusWmi> av; using (var wmi = new ServiceWmi <DtoAntiVirusWmi>(new DtoAntiVirusWmi(), "root\\SecurityCenter2")) { av = wmi.GetObjectList(); } var avInventoryList = new List <DtoAntiVirusInventory>(); foreach (var a in av) { var avInventory = new DtoAntiVirusInventory(); string provider; string realTimeScanner; string upToDate; try { avInventory.DisplayName = a.DisplayName; var hex = a.ProductState.ToString("X6"); var productState = a.ProductState.ToString(); avInventory.ProductState = Convert.ToInt32(productState); provider = hex.Substring(0, 2); realTimeScanner = hex.Substring(2, 2); upToDate = hex.Substring(4, 2); } catch { //ignored continue; } switch (provider) { case "05": case "07": avInventory.Provider = "AntiVirus-Firewall"; break; case "04": case "06": avInventory.Provider = "AntiVirus"; break; default: avInventory.Provider = "Unknown"; break; } switch (realTimeScanner) { case "00": avInventory.RealtimeScanner = "Off"; break; case "01": avInventory.RealtimeScanner = "Expired"; break; case "10": avInventory.RealtimeScanner = "On"; break; case "11": avInventory.RealtimeScanner = "Snoozed"; break; default: avInventory.Provider = "Unknown"; break; } switch (upToDate) { case "00": avInventory.DefinitionStatus = "Up To Date"; break; case "10": avInventory.DefinitionStatus = "Out Of Date"; break; default: avInventory.DefinitionStatus = "Unknown"; break; } avInventoryList.Add(avInventory); } collection.AntiVirus = avInventoryList; /* * https://gallery.technet.microsoft.com/scriptcenter/Get-the-status-of-4b748f25#content * $SECURITY_PROVIDER = switch ($WSC_SECURITY_PROVIDER) * { * 0 {"NONE"} * 1 {"FIREWALL"} * 2 {"AUTOUPDATE_SETTINGS"} * 4 {"ANTIVIRUS"} * 8 {"ANTISPYWARE"} * 16 {"INTERNET_SETTINGS"} * 32 {"USER_ACCOUNT_CONTROL"} * 64 {"SERVICE"} * default {"UNKNOWN"} * } * * * $RealTimeProtectionStatus = switch ($WSC_SECURITY_PRODUCT_STATE) * { * "00" {"OFF"} * "01" {"EXPIRED"} * "10" {"ON"} * "11" {"SNOOZED"} * default {"UNKNOWN"} * } * * $DefinitionStatus = switch ($WSC_SECURITY_SIGNATURE_STATUS) * { * "00" {"UP_TO_DATE"} * "10" {"OUT_OF_DATE"} * default {"UNKNOWN"} * } */ }
public void Search(DtoInventoryCollection collection) { using (var wmi = new ServiceWmi <DtoOsWmi>(new DtoOsWmi())) { var wmiInfo = wmi.Execute(); var osInventory = new DtoOsInventory(); try { osInventory.BuildNumber = wmiInfo.BuildNumber; osInventory.Caption = wmiInfo.Caption; osInventory.OSArchitecture = wmiInfo.OSArchitecture; osInventory.ServicePackMajorVersion = wmiInfo.ServicePackMajorVersion; osInventory.ServicePackMinorVersion = wmiInfo.ServicePackMinorVersion; osInventory.Version = wmiInfo.Version; osInventory.LocalTimeZone = TimeZone.CurrentTimeZone.StandardName; collection.Os = osInventory; } catch (Exception ex) { Logger.Error("Could Not Parse OS Inventory"); Logger.Error(ex.Message); } try { //get release id from registry var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); if (key != null) { osInventory.ReleaseId = Convert.ToString(key.GetValue("ReleaseId")); } //get uac status from registry var uacKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"); if (uacKey != null) { var consentPromptBehavior = uacKey.GetValue("ConsentPromptBehaviorAdmin"); var promptOnSecureDesktop = uacKey.GetValue("PromptOnSecureDesktop"); if (consentPromptBehavior != null && promptOnSecureDesktop != null) { var stringConsent = consentPromptBehavior.ToString(); var stringPrompt = promptOnSecureDesktop.ToString(); if (stringConsent.Equals("0") && stringPrompt.Equals("0")) { collection.Os.UacStatus = "Never Notify"; } else if (stringConsent.Equals("5") && stringPrompt.Equals("0")) { collection.Os.UacStatus = "Notify Changes"; } else if (stringConsent.Equals("5") && stringPrompt.Equals("1")) { collection.Os.UacStatus = "Notify Changes (Dim)"; } else if (stringConsent.Equals("2") && stringPrompt.Equals("0")) { collection.Os.UacStatus = "Always Notify"; } else { collection.Os.UacStatus = "Unknown"; } } } //get sus server from registry var susKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"); if (susKey != null) { osInventory.UpdateServer = Convert.ToString(susKey.GetValue("WUServer")); osInventory.SUStargetGroup = Convert.ToString(susKey.GetValue("TargetGroup")); } collection.Os = osInventory; } catch (Exception ex) { Logger.Error("Could Not Parse OS Inventory"); Logger.Error(ex.Message); } try { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); watcher.PositionChanged += (sender, e) => { var coordinate = e.Position.Location; collection.Os.Latitude = coordinate.Latitude.ToString(CultureInfo.InvariantCulture); collection.Os.Longitude = coordinate.Longitude.ToString(CultureInfo.InvariantCulture); collection.Os.LastLocationUpdateUtc = e.Position.Timestamp.DateTime; }; watcher.TryStart(true, TimeSpan.FromMilliseconds(10000)); collection.Os.LocationEnabled = watcher.Permission == GeoPositionPermission.Granted; } catch { //ignored } } }
public void Search(DtoInventoryCollection collection) { var list = new List <DtoWindowsUpdateInventory>(); try { var updateSession = new UpdateSession(); var updateSearchResult = updateSession.CreateUpdateSearcher(); var count = updateSearchResult.GetTotalHistoryCount(); var history = updateSearchResult.QueryHistory(0, count); for (var i = 0; i < count; ++i) { var update = new DtoWindowsUpdateInventory { IsInstalled = true }; update.Title = history[i].Title; update.UpdateId = history[i].UpdateIdentity.UpdateID; update.LastDeploymentChangeTime = history[i].Date.ToString(CultureInfo.InvariantCulture); if (!string.IsNullOrEmpty(update.Title)) { list.Add(update); } } } catch { //ignored } try { var uSession = new UpdateSession(); var uSearcher = uSession.CreateUpdateSearcher(); uSearcher.Online = true; uSearcher.ServerSelection = ServerSelection.ssWindowsUpdate; var searchResults = uSearcher.Search("IsInstalled=1 AND IsHidden=0"); foreach (IUpdate u in searchResults.Updates) { var update = new DtoWindowsUpdateInventory() { IsInstalled = true }; update.Title = u.Title; update.LastDeploymentChangeTime = u.LastDeploymentChangeTime.ToString(CultureInfo.InvariantCulture); update.UpdateId = u.Identity.UpdateID; list.Add(update); } } catch { //ignored } collection.WindowsUpdates.AddRange(list.GroupBy(x => new { x.Title }).Select(g => g.First()).ToList()); using (var wmi = new ServiceWmi <DtoInstalledUpdatesWmi>(new DtoInstalledUpdatesWmi())) { var wmiUpdates = wmi.GetObjectList(); foreach (var wmiUpdate in wmiUpdates) { if (collection.WindowsUpdates.Any(wu => wu.Title.Contains(wmiUpdate.HotFixID))) { continue; } var update = new DtoWindowsUpdateInventory() { IsInstalled = true }; update.Title = wmiUpdate.HotFixID; update.LastDeploymentChangeTime = wmiUpdate.InstalledOn; collection.WindowsUpdates.Add(update); } } }