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 <DtoComputerSystemInventory>(new DtoComputerSystemInventory())) { collection.ComputerSystem = wmi.Execute(); } }
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(); } }
//This is called from the printer install module to verify the printer installed public List <DtoPrinterInventory> GetInstalledPrinters() { var printers = new List <DtoPrinterInventory>(); using (var wmi = new ServiceWmi <DtoPrinterInventory>(new DtoPrinterInventory())) { printers = wmi.GetObjectList(); } var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Connections"); if (key == null) { return(printers); } 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")); printers.Add(new DtoPrinterInventory { SystemName = server, Name = printerPath, ShareName = printerName }); } return(printers); }
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 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 <DtoBiosInventory>(new DtoBiosInventory())) { collection.Bios = wmi.Execute(); } }
public List <DtoPrinterInventory> GetInstalledPrintersWmiOnly() { var printers = new List <DtoPrinterInventory>(); using (var wmi = new ServiceWmi <DtoPrinterInventory>(new DtoPrinterInventory())) { printers = wmi.GetObjectList(); } return(printers); }
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; } } }
private DtoClientFileHash GetFileForArch() { string osArch; using (var wmi = new ServiceWmi <DtoOsWmi>(new DtoOsWmi())) { var wmiInfo = wmi.Execute(); osArch = wmiInfo.OSArchitecture; } if (osArch.Contains("64")) { foreach (var file in _module.Files) { if (file.FileName.ToLower().Contains("-x64")) { return(file); } } } else if (osArch.Contains("32")) { foreach (var file in _module.Files) { if (file.FileName.ToLower().Contains("-x86")) { return(file); } } } else { Logger.Debug("Could Not Determine Current Os Architecture For Update Selection. Using First File."); return(_module.Files.OrderBy(x => x.FileName).FirstOrDefault()); } Logger.Debug("Could Not Find A File Designated For This Architecture. Using First File."); return(_module.Files.OrderBy(x => x.FileName).FirstOrDefault()); }
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) { 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); } } }
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 } } }