public static List <Monitor> Enumerate(ManagementScope Scope)
        {
            var result = new List <Monitor>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM WmiMonitorID");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                var queryList = queryCollection.Cast <ManagementObject>().ToList();
                foreach (ManagementObject m in queryList)
                {
                    var mm = string.Empty;
                    var sn = string.Empty;
                    var mn = string.Empty;
                    try { mm = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["UserFriendlyName"]).Replace("\0", "").Replace("SERIES", "").Replace("Series", "").Replace("ACER", "").Replace("HWP ", "").Replace("DELL ", "").TrimStart().TrimEnd(); } catch (Exception) { }
                    try { sn = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["SerialNumberID"]).Replace("\0", "").TrimStart().TrimEnd(); } catch (Exception) { }
                    try { mn = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["ManufacturerName"]).Replace("\0", "").Replace("VSC", "ViewSonic").Replace("ACR", "Acer").Replace("DEL", "Dell").Replace("PHL", "Philips").TrimStart().TrimEnd(); } catch (Exception) { }
                    result.Add(new Monitor()
                    {
                        MonitorModel = StringFormatting.CleanInvalidXmlChars(mm), MonitorSerialNumber = StringFormatting.CleanInvalidXmlChars(sn), Manufacturer = StringFormatting.CleanInvalidXmlChars(mn)
                    });
                }
            }
            catch (Exception) { }
            return(result);
        }
        public static List <LogicalDrive> Enumerate(ManagementScope Scope)
        {
            var result = new List <LogicalDrive>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LogicalDisk");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["Description"] != null)
                    {
                        if (m["Description"].ToString() == "Local Fixed Disk" || m["Description"].ToString() == "Локальный несъемный диск")
                        {
                            result.Add(new LogicalDrive
                            {
                                Letter         = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                AviailableSize = m["FreeSpace"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["FreeSpace"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty,
                                TotalSize      = m["Size"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["Size"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty
                            });
                        }
                    }
                }
            }
            catch (Exception) { }
            return(result.OrderBy(x => x.Letter).ToList());
        }
        public static WindowsInformation Enumerate(ManagementScope Scope)
        {
            var result = new WindowsInformation();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.WindowsDirectory = m["WindowsDirectory"] != null?StringFormatting.CleanInvalidXmlChars(m["WindowsDirectory"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.Name = m["Caption"] != null?StringFormatting.CleanInvalidXmlChars(m["Caption"].ToString().Replace(" (Registered Trademark)", "")).TrimStart().TrimEnd() : string.Empty;

                    result.Version = m["Version"] != null?StringFormatting.CleanInvalidXmlChars(m["Version"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.OSArchitecture = m["OSArchitecture"] != null?StringFormatting.CleanInvalidXmlChars(m["OSArchitecture"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.Manufacturer = m["Manufacturer"] != null?StringFormatting.CleanInvalidXmlChars(m["Manufacturer"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.InstallDate = m["InstallDate"] != null?ManagementDateTimeConverter.ToDateTime(StringFormatting.CleanInvalidXmlChars(m["InstallDate"].ToString()).TrimStart().TrimEnd()).ToString() : string.Empty;

                    result.AviailableMemory = m["FreePhysicalMemory"] != null ? ((double)((UInt64)m["FreePhysicalMemory"]) / 1024 / 1024).ToString("0.00 Gb").TrimStart().TrimEnd() : string.Empty;
                }
            }
            catch (Exception) { }
            return(result);
        }
        public static List <PhysicalDrive> Enumerate(ManagementScope Scope)
        {
            var result = new List <PhysicalDrive>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_DiskDrive");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.Add(new PhysicalDrive
                    {
                        Model        = m["Model"] != null ? StringFormatting.CleanInvalidXmlChars(m["Model"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        SerialNumber = m["SerialNumber"] != null ? StringFormatting.CleanInvalidXmlChars(m["SerialNumber"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        Size         = m["Size"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["Size"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty
                    });
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <PhysicalDrive>());
            }
        }
Beispiel #5
0
        public static List <VideoController> Enumerate(ManagementScope Scope)
        {
            var result = new List <VideoController>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_VideoController");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.Add(new VideoController
                    {
                        Name                 = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        VideoProcessor       = m["VideoProcessor"] != null ? StringFormatting.CleanInvalidXmlChars(m["VideoProcessor"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        VideoModeDescription = m["VideoModeDescription"] != null ? StringFormatting.CleanInvalidXmlChars(m["VideoModeDescription"].ToString()).TrimStart().TrimEnd() : string.Empty
                    });
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <VideoController>());
            }
        }
Beispiel #6
0
        public static List <SoftwareLicensingProduct> Enumerate(ManagementScope Scope)
        {
            var result = new List <SoftwareLicensingProduct>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM SoftwareLicensingProduct");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["Name"] != null && m["PartialProductKey"] != null)
                    {
                        if (m["Name"].ToString() != string.Empty && m["PartialProductKey"].ToString() != string.Empty)
                        {
                            var LicenseStatus = m["LicenseStatus"] != null?int.Parse(m["LicenseStatus"].ToString()) : -1;

                            var ProductKeyID = string.Empty;
                            try { ProductKeyID = m["ProductKeyID2"] != null?StringFormatting.CleanInvalidXmlChars(m["ProductKeyID2"].ToString()).TrimStart().TrimEnd() : string.Empty; } catch (Exception) { }
                            result.Add(new SoftwareLicensingProduct
                            {
                                Name              = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                Description       = m["Description"] != null ? StringFormatting.CleanInvalidXmlChars(m["Description"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                LicenseFamily     = m["LicenseFamily"] != null ? StringFormatting.CleanInvalidXmlChars(m["LicenseFamily"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                PatrialProductKey = m["PartialProductKey"] != null ? StringFormatting.CleanInvalidXmlChars(m["PartialProductKey"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                ProductKeyID      = ProductKeyID,
                                LicenseStatus     = LicenseStatus switch
                                {
                                    -1 => "Unknown",
                                    0 => "Unlicensed",
                                    1 => "Licensed",
                                    2 => "OOBGrace",
                                    3 => "OOTGrace",
                                    4 => "NonGenuineGrace",
                                    5 => "Notification",
                                    _ => ""
                                }
                            });
                        }
        public static List <NetworkAdapter> Enumerate(ManagementScope Scope)
        {
            var result = new List <NetworkAdapter>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["IPEnabled"] != null && StringFormatting.CleanInvalidXmlChars(m["IPEnabled"].ToString()).ToLower() != "false")
                    {
                        result.Add(new NetworkAdapter
                        {
                            Adapter        = m["Description"] != null ? StringFormatting.CleanInvalidXmlChars(m["Description"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            MAC            = m["MACAddress"] != null ? StringFormatting.CleanInvalidXmlChars(m["MACAddress"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            DHCP_Enabled   = m["DHCPEnabled"] != null ? StringFormatting.CleanInvalidXmlChars(m["DHCPEnabled"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            IPAddress      = m["IPAddress"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["IPAddress"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            SubnetMasks    = m["IPSubnet"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["IPSubnet"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            DefaultGeteway = m["DefaultIPGateway"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["DefaultIPGateway"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            DHCP_ServerIP  = m["DHCPServer"] != null ? StringFormatting.CleanInvalidXmlChars(m["DHCPServer"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        });
                    }
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <NetworkAdapter>());
            }
        }