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 <DtoBitlockerInventory>(new DtoBitlockerInventory(), "root\\cimv2\\security\\microsoftvolumeencryption")) { collection.Bitlocker = wmi.GetObjectList(); } }
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 } } } }
//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 <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 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) { 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); } } }