Пример #1
0
        public static IEnumerable <LogicalFile> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_LogicalFile");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new LogicalFile
                       {
                           AccessMask          = (uint)(managementObject.Properties["AccessMask"]?.Value ?? default(uint)),
                           Archive             = (bool)(managementObject.Properties["Archive"]?.Value ?? default(bool)),
                           Caption             = (string)(managementObject.Properties["Caption"]?.Value),
                           Compressed          = (bool)(managementObject.Properties["Compressed"]?.Value ?? default(bool)),
                           CompressionMethod   = (string)(managementObject.Properties["CompressionMethod"]?.Value),
                           CreationClassName   = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           CreationDate        = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["CreationDate"]?.Value as string ?? "00010102000000.000000+060"),
                           CsCreationClassName = (string)(managementObject.Properties["CSCreationClassName"]?.Value),
                           CsName                = (string)(managementObject.Properties["CSName"]?.Value),
                           Description           = (string)(managementObject.Properties["Description"]?.Value),
                           Drive                 = (string)(managementObject.Properties["Drive"]?.Value),
                           EightDotThreeFileName = (string)(managementObject.Properties["EightDotThreeFileName"]?.Value),
                           Encrypted             = (bool)(managementObject.Properties["Encrypted"]?.Value ?? default(bool)),
                           EncryptionMethod      = (string)(managementObject.Properties["EncryptionMethod"]?.Value),
                           Extension             = (string)(managementObject.Properties["Extension"]?.Value),
                           FileName              = (string)(managementObject.Properties["FileName"]?.Value),
                           FileSize              = (ulong)(managementObject.Properties["FileSize"]?.Value ?? default(ulong)),
                           FileType              = (string)(managementObject.Properties["FileType"]?.Value),
                           FsCreationClassName   = (string)(managementObject.Properties["FSCreationClassName"]?.Value),
                           FsName                = (string)(managementObject.Properties["FSName"]?.Value),
                           Hidden                = (bool)(managementObject.Properties["Hidden"]?.Value ?? default(bool)),
                           InstallDate           = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           InUseCount            = (ulong)(managementObject.Properties["InUseCount"]?.Value ?? default(ulong)),
                           LastAccessed          = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastAccessed"]?.Value as string ?? "00010102000000.000000+060"),
                           LastModified          = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastModified"]?.Value as string ?? "00010102000000.000000+060"),
                           Name      = (string)(managementObject.Properties["Name"]?.Value),
                           Path      = (string)(managementObject.Properties["Path"]?.Value),
                           Readable  = (bool)(managementObject.Properties["Readable"]?.Value ?? default(bool)),
                           Status    = (string)(managementObject.Properties["Status"]?.Value),
                           System    = (bool)(managementObject.Properties["System"]?.Value ?? default(bool)),
                           Writeable = (bool)(managementObject.Properties["Writeable"]?.Value ?? default(bool))
                       }
            }
            ;
        }
    }
Пример #2
0
        public TimeSpan getUpTime()
        {
            var mo         = new ManagementObject(@"\\.\root\cimv2:Win32_OperatingSystem=@");
            var lastBootUp = ManagementDateTimeConverter.ToDateTime(mo["LastBootUpTime"].ToString());

            return(DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime());


            /*
             * return new TimeSpan(0, 0, 0, Environment.TickCount);
             */

            /*PerformanceCounter pc = new PerformanceCounter("System", "System Up Time");
             * pc.NextValue();
             * int uptime = (int)pc.NextValue();
             * return new TimeSpan(0, 0, uptime);*/
        }
Пример #3
0
        public static IEnumerable <InfraredController> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_InfraredController");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new InfraredController
                       {
                           Availability           = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Caption                = (string)managementObject.Properties["Caption"]?.Value,
                           ConfigManagerErrorCode =
                               (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig =
                               (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName = (string)managementObject.Properties["CreationClassName"]?.Value,
                           Description       = (string)managementObject.Properties["Description"]?.Value,
                           DeviceId          = (string)managementObject.Properties["DeviceID"]?.Value,
                           ErrorCleared      = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription  = (string)managementObject.Properties["ErrorDescription"]?.Value,
                           InstallDate       =
                               ManagementDateTimeConverter.ToDateTime(
                                   managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LastErrorCode       = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           MaxNumberControlled =
                               (uint)(managementObject.Properties["MaxNumberControlled"]?.Value ?? default(uint)),
                           Name        = (string)managementObject.Properties["Name"]?.Value,
                           PnpDeviceId = (string)managementObject.Properties["PNPDeviceID"]?.Value,
                           PowerManagementCapabilities =
                               (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported =
                               (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           ProtocolSupported =
                               (ushort)(managementObject.Properties["ProtocolSupported"]?.Value ?? default(ushort)),
                           Status     = (string)managementObject.Properties["Status"]?.Value,
                           StatusInfo = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName = (string)managementObject.Properties["SystemCreationClassName"]?.Value,
                           SystemName      = (string)managementObject.Properties["SystemName"]?.Value,
                           TimeOfLastReset = ManagementDateTimeConverter.ToDateTime(
                               managementObject.Properties["TimeOfLastReset"]?.Value as string ?? "00010102000000.000000+060")
                       }
            }
            ;
        }
    }
Пример #4
0
        public static IEnumerable <PowerSupply> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_PowerSupply");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new PowerSupply
                       {
                           ActiveInputVoltage      = (ushort)(managementObject.Properties["ActiveInputVoltage"]?.Value ?? default(ushort)),
                           Availability            = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           ConfigManagerErrorCode  = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName       = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceId                = (string)(managementObject.Properties["DeviceID"]?.Value),
                           ErrorCleared            = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription        = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           InstallDate             = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           IsSwitchingSupply       = (bool)(managementObject.Properties["IsSwitchingSupply"]?.Value ?? default(bool)),
                           LastErrorCode           = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           Name        = (string)(managementObject.Properties["Name"]?.Value),
                           PnpDeviceId = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           Range1InputFrequencyHigh    = (uint)(managementObject.Properties["Range1InputFrequencyHigh"]?.Value ?? default(uint)),
                           Range1InputFrequencyLow     = (uint)(managementObject.Properties["Range1InputFrequencyLow"]?.Value ?? default(uint)),
                           Range1InputVoltageHigh      = (uint)(managementObject.Properties["Range1InputVoltageHigh"]?.Value ?? default(uint)),
                           Range1InputVoltageLow       = (uint)(managementObject.Properties["Range1InputVoltageLow"]?.Value ?? default(uint)),
                           Range2InputFrequencyHigh    = (uint)(managementObject.Properties["Range2InputFrequencyHigh"]?.Value ?? default(uint)),
                           Range2InputFrequencyLow     = (uint)(managementObject.Properties["Range2InputFrequencyLow"]?.Value ?? default(uint)),
                           Range2InputVoltageHigh      = (uint)(managementObject.Properties["Range2InputVoltageHigh"]?.Value ?? default(uint)),
                           Range2InputVoltageLow       = (uint)(managementObject.Properties["Range2InputVoltageLow"]?.Value ?? default(uint)),
                           Status     = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName           = (string)(managementObject.Properties["SystemName"]?.Value),
                           TotalOutputPower     = (uint)(managementObject.Properties["TotalOutputPower"]?.Value ?? default(uint)),
                           TypeOfRangeSwitching = (ushort)(managementObject.Properties["TypeOfRangeSwitching"]?.Value ?? default(ushort))
                       }
            }
            ;
        }
    }
        public static DateTime?ToDateTime(ManagementBaseObject baseObj,
                                          string property)
        {
            if (!PropertyExists(baseObj, property))
            {
                return(null);
            }
            try { if (baseObj[property] == null)
                  {
                      return(null);
                  }
            }
            catch { return(null); }
            DateTime dt = ManagementDateTimeConverter.ToDateTime(baseObj[property].ToString());

            return(dt);
        }
Пример #6
0
        /// <summary>
        /// Converts a WMI DateTime string to a C# DateTime object
        /// </summary>
        /// <param name="ManagementDateTime">The WMI DateTime string.</param>
        /// <returns>System.Nullable{DateTime}.</returns>
        public static DateTime?WMIDateToDateTime(string ManagementDateTime)
        {
            try
            {
                if (string.IsNullOrEmpty(ManagementDateTime))
                {
                    return(null);
                }
                else
                {
                    return(ManagementDateTimeConverter.ToDateTime(ManagementDateTime) as DateTime?);
                }
            }
            catch { }

            return(null);
        }
Пример #7
0
        public static IEnumerable <Bios> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_BIOS");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new Bios
                       {
                           BiosCharacteristics            = (ushort[])(managementObject.Properties["BiosCharacteristics"]?.Value ?? new ushort[0]),
                           BiosVersion                    = (string[])(managementObject.Properties["BIOSVersion"]?.Value ?? new string[0]),
                           BuildNumber                    = (string)(managementObject.Properties["BuildNumber"]?.Value),
                           Caption                        = (string)(managementObject.Properties["Caption"]?.Value),
                           CodeSet                        = (string)(managementObject.Properties["CodeSet"]?.Value),
                           CurrentLanguage                = (string)(managementObject.Properties["CurrentLanguage"]?.Value),
                           Description                    = (string)(managementObject.Properties["Description"]?.Value),
                           EmbeddedControllerMajorVersion = (byte)(managementObject.Properties["EmbeddedControllerMajorVersion"]?.Value ?? default(byte)),
                           EmbeddedControllerMinorVersion = (byte)(managementObject.Properties["EmbeddedControllerMinorVersion"]?.Value ?? default(byte)),
                           IdentificationCode             = (string)(managementObject.Properties["IdentificationCode"]?.Value),
                           InstallableLanguages           = (ushort)(managementObject.Properties["InstallableLanguages"]?.Value ?? default(ushort)),
                           InstallDate                    = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LanguageEdition                = (string)(managementObject.Properties["LanguageEdition"]?.Value),
                           ListOfLanguages                = (string[])(managementObject.Properties["ListOfLanguages"]?.Value ?? new string[0]),
                           Manufacturer                   = (string)(managementObject.Properties["Manufacturer"]?.Value),
                           Name                   = (string)(managementObject.Properties["Name"]?.Value),
                           OtherTargetOs          = (string)(managementObject.Properties["OtherTargetOS"]?.Value),
                           PrimaryBios            = (bool)(managementObject.Properties["PrimaryBIOS"]?.Value ?? default(bool)),
                           ReleaseDate            = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["ReleaseDate"]?.Value as string ?? "00010102000000.000000+060"),
                           SerialNumber           = (string)(managementObject.Properties["SerialNumber"]?.Value),
                           SmbiosbiosVersion      = (string)(managementObject.Properties["SMBIOSBIOSVersion"]?.Value),
                           SmbiosMajorVersion     = (ushort)(managementObject.Properties["SMBIOSMajorVersion"]?.Value ?? default(ushort)),
                           SmbiosMinorVersion     = (ushort)(managementObject.Properties["SMBIOSMinorVersion"]?.Value ?? default(ushort)),
                           SmbiosPresent          = (bool)(managementObject.Properties["SMBIOSPresent"]?.Value ?? default(bool)),
                           SoftwareElementId      = (string)(managementObject.Properties["SoftwareElementID"]?.Value),
                           SoftwareElementState   = (ushort)(managementObject.Properties["SoftwareElementState"]?.Value ?? default(ushort)),
                           Status                 = (string)(managementObject.Properties["Status"]?.Value),
                           SystemBiosMajorVersion = (byte)(managementObject.Properties["SystemBiosMajorVersion"]?.Value ?? default(byte)),
                           SystemBiosMinorVersion = (byte)(managementObject.Properties["SystemBiosMinorVersion"]?.Value ?? default(byte)),
                           TargetOperatingSystem  = (ushort)(managementObject.Properties["TargetOperatingSystem"]?.Value ?? default(ushort)),
                           Version                = (string)(managementObject.Properties["Version"]?.Value)
                       }
            }
            ;
        }
    }
Пример #8
0
        public static IEnumerable <Win32ScsiController> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_SCSIController");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new Win32ScsiController
                       {
                           Availability            = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           ConfigManagerErrorCode  = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           ControllerTimeouts      = (uint)(managementObject.Properties["ControllerTimeouts"]?.Value ?? default(uint)),
                           CreationClassName       = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceId                = (string)(managementObject.Properties["DeviceID"]?.Value),
                           DeviceMap               = (string)(managementObject.Properties["DeviceMap"]?.Value),
                           DriverName              = (string)(managementObject.Properties["DriverName"]?.Value),
                           ErrorCleared            = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription        = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           HardwareVersion         = (string)(managementObject.Properties["HardwareVersion"]?.Value),
                           Index               = (uint)(managementObject.Properties["Index"]?.Value ?? default(uint)),
                           InstallDate         = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LastErrorCode       = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           Manufacturer        = (string)(managementObject.Properties["Manufacturer"]?.Value),
                           MaxDataWidth        = (uint)(managementObject.Properties["MaxDataWidth"]?.Value ?? default(uint)),
                           MaxNumberControlled = (uint)(managementObject.Properties["MaxNumberControlled"]?.Value ?? default(uint)),
                           MaxTransferRate     = (ulong)(managementObject.Properties["MaxTransferRate"]?.Value ?? default(ulong)),
                           Name        = (string)(managementObject.Properties["Name"]?.Value),
                           PnpDeviceId = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           ProtectionManagement        = (ushort)(managementObject.Properties["ProtectionManagement"]?.Value ?? default(ushort)),
                           ProtocolSupported           = (ushort)(managementObject.Properties["ProtocolSupported"]?.Value ?? default(ushort)),
                           Status     = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName      = (string)(managementObject.Properties["SystemName"]?.Value),
                           TimeOfLastReset = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["TimeOfLastReset"]?.Value as string ?? "00010102000000.000000+060")
                       }
            }
            ;
        }
    }
Пример #9
0
        public static IEnumerable <Battery> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_Battery");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new Battery
                       {
                           Availability             = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           BatteryStatus            = (ushort)(managementObject.Properties["BatteryStatus"]?.Value ?? default(ushort)),
                           Caption                  = (string)(managementObject.Properties["Caption"]?.Value),
                           Chemistry                = (ushort)(managementObject.Properties["Chemistry"]?.Value ?? default(ushort)),
                           ConfigManagerErrorCode   = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig  = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName        = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Description              = (string)(managementObject.Properties["Description"]?.Value),
                           DesignCapacity           = (uint)(managementObject.Properties["DesignCapacity"]?.Value ?? default(uint)),
                           DesignVoltage            = (ulong)(managementObject.Properties["DesignVoltage"]?.Value ?? default(ulong)),
                           DeviceId                 = (string)(managementObject.Properties["DeviceID"]?.Value),
                           ErrorCleared             = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription         = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           EstimatedChargeRemaining = (ushort)(managementObject.Properties["EstimatedChargeRemaining"]?.Value ?? default(ushort)),
                           EstimatedRunTime         = (uint)(managementObject.Properties["EstimatedRunTime"]?.Value ?? default(uint)),
                           ExpectedLife             = (uint)(managementObject.Properties["ExpectedLife"]?.Value ?? default(uint)),
                           FullChargeCapacity       = (uint)(managementObject.Properties["FullChargeCapacity"]?.Value ?? default(uint)),
                           InstallDate              = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LastErrorCode            = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           MaxRechargeTime          = (uint)(managementObject.Properties["MaxRechargeTime"]?.Value ?? default(uint)),
                           Name        = (string)(managementObject.Properties["Name"]?.Value),
                           PnpDeviceId = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           SmartBatteryVersion         = (string)(managementObject.Properties["SmartBatteryVersion"]?.Value),
                           Status     = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName       = (string)(managementObject.Properties["SystemName"]?.Value),
                           TimeOnBattery    = (uint)(managementObject.Properties["TimeOnBattery"]?.Value ?? default(uint)),
                           TimeToFullCharge = (uint)(managementObject.Properties["TimeToFullCharge"]?.Value ?? default(uint))
                       }
            }
            ;
        }
    }
Пример #10
0
        public static IEnumerable <VideoConfiguration> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_VideoConfiguration");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new VideoConfiguration
                       {
                           ActualColorResolution = (uint)(managementObject.Properties["ActualColorResolution"]?.Value ?? default(uint)),
                           AdapterChipType       = (string)(managementObject.Properties["AdapterChipType"]?.Value),
                           AdapterCompatibility  = (string)(managementObject.Properties["AdapterCompatibility"]?.Value),
                           AdapterDacType        = (string)(managementObject.Properties["AdapterDACType"]?.Value),
                           AdapterDescription    = (string)(managementObject.Properties["AdapterDescription"]?.Value),
                           AdapterRam            = (uint)(managementObject.Properties["AdapterRAM"]?.Value ?? default(uint)),
                           AdapterType           = (string)(managementObject.Properties["AdapterType"]?.Value),
                           BitsPerPixel          = (uint)(managementObject.Properties["BitsPerPixel"]?.Value ?? default(uint)),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           ColorPlanes             = (uint)(managementObject.Properties["ColorPlanes"]?.Value ?? default(uint)),
                           ColorTableEntries       = (uint)(managementObject.Properties["ColorTableEntries"]?.Value ?? default(uint)),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceSpecificPens      = (uint)(managementObject.Properties["DeviceSpecificPens"]?.Value ?? default(uint)),
                           DriverDate              = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["DriverDate"]?.Value as string ?? "00010102000000.000000+060"),
                           HorizontalResolution    = (uint)(managementObject.Properties["HorizontalResolution"]?.Value ?? default(uint)),
                           InfFilename             = (string)(managementObject.Properties["InfFilename"]?.Value),
                           InfSection              = (string)(managementObject.Properties["InfSection"]?.Value),
                           InstalledDisplayDrivers = (string)(managementObject.Properties["InstalledDisplayDrivers"]?.Value),
                           MonitorManufacturer     = (string)(managementObject.Properties["MonitorManufacturer"]?.Value),
                           MonitorType             = (string)(managementObject.Properties["MonitorType"]?.Value),
                           Name = (string)(managementObject.Properties["Name"]?.Value),
                           PixelsPerXLogicalInch = (uint)(managementObject.Properties["PixelsPerXLogicalInch"]?.Value ?? default(uint)),
                           PixelsPerYLogicalInch = (uint)(managementObject.Properties["PixelsPerYLogicalInch"]?.Value ?? default(uint)),
                           RefreshRate           = (uint)(managementObject.Properties["RefreshRate"]?.Value ?? default(uint)),
                           ScanMode             = (string)(managementObject.Properties["ScanMode"]?.Value),
                           ScreenHeight         = (uint)(managementObject.Properties["ScreenHeight"]?.Value ?? default(uint)),
                           ScreenWidth          = (uint)(managementObject.Properties["ScreenWidth"]?.Value ?? default(uint)),
                           SettingId            = (string)(managementObject.Properties["SettingID"]?.Value),
                           SystemPaletteEntries = (uint)(managementObject.Properties["SystemPaletteEntries"]?.Value ?? default(uint)),
                           VerticalResolution   = (uint)(managementObject.Properties["VerticalResolution"]?.Value ?? default(uint))
                       }
            }
            ;
        }
    }
Пример #11
0
        /// <summary>
        /// Returns the process id of the process with the given name that's closest to the date given.
        /// </summary>
        /// <param name="name">Name of the process to search for.</param>
        /// <param name="date">Date to filter from. Only processes with a greater then date will be returned.</param>
        /// <param name="timeout">time in seconds to retry looking for the process</param>
        /// <returns>Process Id of the process.</returns>
        public static int GetProcessByNameAfterDate(string name, DateTime date, int timeout = 15)
        {
            var game_process_date = DateTime.MaxValue;
            var stopwatch_timeout = new Stopwatch();

            int seconds_passed  = 0;
            int game_process_id = 0;

            var wmiq = String.Format(CultureInfo.InvariantCulture,
                                     "SELECT ProcessId, CreationDate FROM Win32_Process WHERE CreationDate > '{0}' AND Name LIKE '{1}%'",
                                     ManagementDateTimeConverter.ToDmtfDateTime(date).ToString(CultureInfo.InvariantCulture), name);

            using (var searcher = new ManagementObjectSearcher(wmiq))
            {
                stopwatch_timeout.Restart();


                // Keep looking until timeout is reached or we find a process
                while (game_process_id == 0 && stopwatch_timeout.Elapsed.TotalSeconds < timeout)
                {
                    // Avoids spamming the log with looking for process messages
                    if ((stopwatch_timeout.ElapsedMilliseconds - (seconds_passed * 1000)) > 0)
                    {
                        Logger.Information($"Searching for process '{name}' for '{timeout - seconds_passed}' seconds.");
                        seconds_passed++;
                    }

                    foreach (var result in searcher.Get())
                    {
                        var result_process_id   = Convert.ToInt32(result["ProcessId"], CultureInfo.InvariantCulture);
                        var result_process_date = ManagementDateTimeConverter.ToDateTime(result["CreationDate"].ToString());

                        Logger.Information($"Found game process started at '{result_process_date.ToString("hh:mm:ss.ffff", CultureInfo.InvariantCulture)}' with pid:'{result_process_id}'");

                        // Closest to the given date is the one we return
                        if (result_process_date.Subtract(date).TotalMilliseconds < game_process_date.Subtract(date).TotalMilliseconds)
                        {
                            game_process_id   = result_process_id;
                            game_process_date = result_process_date;
                        }
                    }
                }
            }
            return(game_process_id);
        }
Пример #12
0
        public static IEnumerable <Processor> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_Processor");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new Processor
                       {
                           AddressWidth            = (ushort)(managementObject.Properties["AddressWidth"]?.Value ?? default(ushort)),
                           Availability            = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           ConfigManagerErrorCode  = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName       = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           CurrentClockSpeed       = (uint)(managementObject.Properties["CurrentClockSpeed"]?.Value ?? default(uint)),
                           DataWidth               = (ushort)(managementObject.Properties["DataWidth"]?.Value ?? default(ushort)),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceId                = (string)(managementObject.Properties["DeviceID"]?.Value),
                           ErrorCleared            = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription        = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           Family                      = (ushort)(managementObject.Properties["Family"]?.Value ?? default(ushort)),
                           InstallDate                 = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LastErrorCode               = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           LoadPercentage              = (ushort)(managementObject.Properties["LoadPercentage"]?.Value ?? default(ushort)),
                           MaxClockSpeed               = (uint)(managementObject.Properties["MaxClockSpeed"]?.Value ?? default(uint)),
                           Name                        = (string)(managementObject.Properties["Name"]?.Value),
                           OtherFamilyDescription      = (string)(managementObject.Properties["OtherFamilyDescription"]?.Value),
                           PnpDeviceId                 = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           Role                        = (string)(managementObject.Properties["Role"]?.Value),
                           Status                      = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo                  = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           Stepping                    = (string)(managementObject.Properties["Stepping"]?.Value),
                           SystemCreationClassName     = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName                  = (string)(managementObject.Properties["SystemName"]?.Value),
                           UniqueId                    = (string)(managementObject.Properties["UniqueId"]?.Value),
                           UpgradeMethod               = (ushort)(managementObject.Properties["UpgradeMethod"]?.Value ?? default(ushort))
                       }
            }
            ;
        }
    }
Пример #13
0
        public static IEnumerable <PhysicalFrame> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_PhysicalFrame");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new PhysicalFrame
                       {
                           AudibleAlarm            = (bool)(managementObject.Properties["AudibleAlarm"]?.Value ?? default(bool)),
                           BreachDescription       = (string)(managementObject.Properties["BreachDescription"]?.Value),
                           CableManagementStrategy = (string)(managementObject.Properties["CableManagementStrategy"]?.Value),
                           Caption           = (string)(managementObject.Properties["Caption"]?.Value),
                           CreationClassName = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Depth             = (float)(managementObject.Properties["Depth"]?.Value ?? default(float)),
                           Description       = (string)(managementObject.Properties["Description"]?.Value),
                           Height            = (float)(managementObject.Properties["Height"]?.Value ?? default(float)),
                           HotSwappable      = (bool)(managementObject.Properties["HotSwappable"]?.Value ?? default(bool)),
                           InstallDate       = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LockPresent       = (bool)(managementObject.Properties["LockPresent"]?.Value ?? default(bool)),
                           Manufacturer      = (string)(managementObject.Properties["Manufacturer"]?.Value),
                           Model             = (string)(managementObject.Properties["Model"]?.Value),
                           Name = (string)(managementObject.Properties["Name"]?.Value),
                           OtherIdentifyingInfo = (string)(managementObject.Properties["OtherIdentifyingInfo"]?.Value),
                           PartNumber           = (string)(managementObject.Properties["PartNumber"]?.Value),
                           PoweredOn            = (bool)(managementObject.Properties["PoweredOn"]?.Value ?? default(bool)),
                           Removable            = (bool)(managementObject.Properties["Removable"]?.Value ?? default(bool)),
                           Replaceable          = (bool)(managementObject.Properties["Replaceable"]?.Value ?? default(bool)),
                           SecurityBreach       = (ushort)(managementObject.Properties["SecurityBreach"]?.Value ?? default(ushort)),
                           SerialNumber         = (string)(managementObject.Properties["SerialNumber"]?.Value),
                           ServiceDescriptions  = (string[])(managementObject.Properties["ServiceDescriptions"]?.Value ?? new string[0]),
                           ServicePhilosophy    = (ushort[])(managementObject.Properties["ServicePhilosophy"]?.Value ?? new ushort[0]),
                           Sku          = (string)(managementObject.Properties["SKU"]?.Value),
                           Status       = (string)(managementObject.Properties["Status"]?.Value),
                           Tag          = (string)(managementObject.Properties["Tag"]?.Value),
                           Version      = (string)(managementObject.Properties["Version"]?.Value),
                           VisibleAlarm = (bool)(managementObject.Properties["VisibleAlarm"]?.Value ?? default(bool)),
                           Weight       = (float)(managementObject.Properties["Weight"]?.Value ?? default(float)),
                           Width        = (float)(managementObject.Properties["Width"]?.Value ?? default(float))
                       }
            }
            ;
        }
    }
Пример #14
0
        /// <summary>
        /// Function that reports the users time logged in and returns this within a Timespan
        /// </summary>
        /// <returns></returns>
        ///
        public static TimeSpan GetUptimeUser()
        {
            ManagementScope          ms    = new ManagementScope("\\root\\cimv2");
            ObjectQuery              oq    = new ObjectQuery("Select * from Win32_Session");
            ManagementObjectSearcher query = new ManagementObjectSearcher(ms, oq);

            ManagementObjectCollection queryCollection = query.Get();
            DateTime lastBootUp = DateTime.Now.ToUniversalTime();

            foreach (ManagementObject mo in queryCollection)
            {
                if (mo["LogonType"].ToString().Equals("2")) //  2 - for logged on User
                {
                    lastBootUp = ManagementDateTimeConverter.ToDateTime(mo["StartTime"].ToString());
                }
            }
            return(DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime());
        }
Пример #15
0
 public TargetData(string target)
 {
     this.target = target;
     InitializeComponent();
     string[] os_data = Handler.collect_target_info(new WMI_OperatingSystem(), target);
     string[] cs_data = Handler.collect_target_info(new WMI_ComputerSystem(), target);
     dataGridView1.Rows.Add(new string[] { "NetBIOS-имя", cs_data[0] });
     dataGridView1.Rows.Add(new string[] { "Производитель", cs_data[1] });
     dataGridView1.Rows.Add(new string[] { "Домен", cs_data[2] });
     dataGridView1.Rows.Add(new string[] { "Модель", cs_data[3] });
     dataGridView1.Rows.Add(new string[] { "Активный пользователь", cs_data[4] });
     dataGridView1.Rows.Add(new string[] { "Объем RAM", cs_data[5] });
     dataGridView1.Rows.Add(new string[] { "Операционная система", os_data[0] });
     dataGridView1.Rows.Add(new string[] { "Дата установки", ManagementDateTimeConverter.ToDateTime(os_data[1]).ToString() });
     dataGridView1.Rows.Add(new string[] { "Время последней загрузки", ManagementDateTimeConverter.ToDateTime(os_data[2]).ToString() });
     dataGridView1.Rows.Add(new string[] { "Количество пользователей", os_data[3] });
     dataGridView1.Rows.Add(new string[] { "Серийный номер ОС", os_data[4] });
 }
Пример #16
0
        private void GetBiosInformation()
        {
            SelectQuery Sq = new SelectQuery("Win32_BIOS");
            ManagementObjectSearcher   mSearcher  = new ManagementObjectSearcher(Sq);
            ManagementObjectCollection collection = mSearcher.Get();

            foreach (ManagementObject obj in collection)
            {
                string relDt = "";

                BiosMakerLabelOutput.Content   = (string)obj["Manufacturer"];
                BiosSerialNumberOutput.Content = (string)obj["SerialNumber"];
                BiosVersionLabelOutput.Content = (string)obj["Version"];
                relDt = (string)obj["ReleaseDate"];
                DateTime dt = ManagementDateTimeConverter.ToDateTime(relDt);
                BiosReleaseDateOutput.Content = dt.ToString("dd-MMM-yyyy");//date format
            }
        }
Пример #17
0
        public static bool TryGetDateTime(this ManagementObject managementObject, string propertyName, out DateTimeOffset value)
        {
            if (TryGetProperty(managementObject, propertyName, out string dmtfDate))
            {
                try
                {
                    value = ManagementDateTimeConverter.ToDateTime(dmtfDate);
                    return(true);
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            value = default;
            return(false);
        }
Пример #18
0
    public static bool smethod_1(string string_0, TimeSpan timeSpan_0)
    {
        if (string_0 == "99999999235959.000000:000")
        {
            return(false);
        }
        bool result;

        try
        {
            result = (ManagementDateTimeConverter.ToTimeSpan(string_0) <= timeSpan_0);
        }
        catch
        {
            result = false;
        }
        return(result);
    }
Пример #19
0
        public static IEnumerable <MagnetoOpticalDrive> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM CIM_MagnetoOpticalDrive");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new MagnetoOpticalDrive
                       {
                           Availability           = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Capabilities           = (ushort[])(managementObject.Properties["Capabilities"]?.Value ?? new ushort[0]),
                           CapabilityDescriptions = (string[])(managementObject.Properties["CapabilityDescriptions"]?.Value ?? new string[0]),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           CompressionMethod       = (string)(managementObject.Properties["CompressionMethod"]?.Value),
                           ConfigManagerErrorCode  = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName       = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           DefaultBlockSize        = (ulong)(managementObject.Properties["DefaultBlockSize"]?.Value ?? default(ulong)),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceId                = (string)(managementObject.Properties["DeviceID"]?.Value),
                           ErrorCleared            = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription        = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           ErrorMethodology        = (string)(managementObject.Properties["ErrorMethodology"]?.Value),
                           InstallDate             = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           LastErrorCode           = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           MaxBlockSize            = (ulong)(managementObject.Properties["MaxBlockSize"]?.Value ?? default(ulong)),
                           MaxMediaSize            = (ulong)(managementObject.Properties["MaxMediaSize"]?.Value ?? default(ulong)),
                           MinBlockSize            = (ulong)(managementObject.Properties["MinBlockSize"]?.Value ?? default(ulong)),
                           Name                        = (string)(managementObject.Properties["Name"]?.Value),
                           NeedsCleaning               = (bool)(managementObject.Properties["NeedsCleaning"]?.Value ?? default(bool)),
                           NumberOfMediaSupported      = (uint)(managementObject.Properties["NumberOfMediaSupported"]?.Value ?? default(uint)),
                           PnpDeviceId                 = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           Status                      = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo                  = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName     = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName                  = (string)(managementObject.Properties["SystemName"]?.Value)
                       }
            }
            ;
        }
    }
Пример #20
0
    // Token: 0x06000073 RID: 115 RVA: 0x00005C0C File Offset: 0x00003E0C
    public static string smethod_0()
    {
        string result;

        try
        {
            string text = string.Empty;
            using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem WHERE Primary='true'"))
            {
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        DateTime         d        = ManagementDateTimeConverter.ToDateTime(managementObject["LastBootUpTime"].ToString());
                        TimeSpan         timeSpan = TimeSpan.FromTicks((DateTime.Now - d).Ticks);
                        text = string.Format("{0}d : {1}h : {2}m : {3}s", new object[]
                        {
                            timeSpan.Days,
                            timeSpan.Hours,
                            timeSpan.Minutes,
                            timeSpan.Seconds
                        });
                    }
                }
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new Exception("Getting uptime failed");
            }
            result = text;
        }
        catch (Exception)
        {
            result = string.Format("{0}d : {1}h : {2}m : {3}s", new object[]
            {
                0,
                0,
                0,
                0
            });
        }
        return(result);
    }
Пример #21
0
        public static IEnumerable <UserProfile> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_UserProfile");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new UserProfile
                       {
                           AppDataRoaming = (dynamic)(managementObject.Properties["AppDataRoaming"]?.Value ?? default(dynamic)),
                           Contacts       = (dynamic)(managementObject.Properties["Contacts"]?.Value ?? default(dynamic)),
                           Desktop        = (dynamic)(managementObject.Properties["Desktop"]?.Value ?? default(dynamic)),
                           Documents      = (dynamic)(managementObject.Properties["Documents"]?.Value ?? default(dynamic)),
                           Downloads      = (dynamic)(managementObject.Properties["Downloads"]?.Value ?? default(dynamic)),
                           Favorites      = (dynamic)(managementObject.Properties["Favorites"]?.Value ?? default(dynamic)),
                           HealthStatus   = (byte)(managementObject.Properties["HealthStatus"]?.Value ?? default(byte)),
                           LastAttemptedProfileDownloadTime = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastAttemptedProfileDownloadTime"]?.Value as string ?? "00010102000000.000000+060"),
                           LastAttemptedProfileUploadTime   = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastAttemptedProfileUploadTime"]?.Value as string ?? "00010102000000.000000+060"),
                           LastBackgroundRegistryUploadTime = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastBackgroundRegistryUploadTime"]?.Value as string ?? "00010102000000.000000+060"),
                           LastDownloadTime  = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastDownloadTime"]?.Value as string ?? "00010102000000.000000+060"),
                           LastUploadTime    = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastUploadTime"]?.Value as string ?? "00010102000000.000000+060"),
                           LastUseTime       = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["LastUseTime"]?.Value as string ?? "00010102000000.000000+060"),
                           Links             = (dynamic)(managementObject.Properties["Links"]?.Value ?? default(dynamic)),
                           Loaded            = (bool)(managementObject.Properties["Loaded"]?.Value ?? default(bool)),
                           LocalPath         = (string)(managementObject.Properties["LocalPath"]?.Value),
                           Music             = (dynamic)(managementObject.Properties["Music"]?.Value ?? default(dynamic)),
                           Pictures          = (dynamic)(managementObject.Properties["Pictures"]?.Value ?? default(dynamic)),
                           RefCount          = (uint)(managementObject.Properties["RefCount"]?.Value ?? default(uint)),
                           RoamingConfigured = (bool)(managementObject.Properties["RoamingConfigured"]?.Value ?? default(bool)),
                           RoamingPath       = (string)(managementObject.Properties["RoamingPath"]?.Value),
                           RoamingPreference = (bool)(managementObject.Properties["RoamingPreference"]?.Value ?? default(bool)),
                           SavedGames        = (dynamic)(managementObject.Properties["SavedGames"]?.Value ?? default(dynamic)),
                           Searches          = (dynamic)(managementObject.Properties["Searches"]?.Value ?? default(dynamic)),
                           Sid       = (string)(managementObject.Properties["SID"]?.Value),
                           Special   = (bool)(managementObject.Properties["Special"]?.Value ?? default(bool)),
                           StartMenu = (dynamic)(managementObject.Properties["StartMenu"]?.Value ?? default(dynamic)),
                           Status    = (uint)(managementObject.Properties["Status"]?.Value ?? default(uint)),
                           Videos    = (dynamic)(managementObject.Properties["Videos"]?.Value ?? default(dynamic))
                       }
            }
            ;
        }
    }
Пример #22
0
        public static IEnumerable <BaseBoard> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_BaseBoard");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new BaseBoard
                       {
                           Caption           = (string)(managementObject.Properties["Caption"]?.Value),
                           ConfigOptions     = (string[])(managementObject.Properties["ConfigOptions"]?.Value ?? new string[0]),
                           CreationClassName = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Depth             = (float)(managementObject.Properties["Depth"]?.Value ?? default(float)),
                           Description       = (string)(managementObject.Properties["Description"]?.Value),
                           Height            = (float)(managementObject.Properties["Height"]?.Value ?? default(float)),
                           HostingBoard      = (bool)(managementObject.Properties["HostingBoard"]?.Value ?? default(bool)),
                           HotSwappable      = (bool)(managementObject.Properties["HotSwappable"]?.Value ?? default(bool)),
                           InstallDate       = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           Manufacturer      = (string)(managementObject.Properties["Manufacturer"]?.Value),
                           Model             = (string)(managementObject.Properties["Model"]?.Value),
                           Name = (string)(managementObject.Properties["Name"]?.Value),
                           OtherIdentifyingInfo = (string)(managementObject.Properties["OtherIdentifyingInfo"]?.Value),
                           PartNumber           = (string)(managementObject.Properties["PartNumber"]?.Value),
                           PoweredOn            = (bool)(managementObject.Properties["PoweredOn"]?.Value ?? default(bool)),
                           Product                 = (string)(managementObject.Properties["Product"]?.Value),
                           Removable               = (bool)(managementObject.Properties["Removable"]?.Value ?? default(bool)),
                           Replaceable             = (bool)(managementObject.Properties["Replaceable"]?.Value ?? default(bool)),
                           RequirementsDescription = (string)(managementObject.Properties["RequirementsDescription"]?.Value),
                           RequiresDaughterBoard   = (bool)(managementObject.Properties["RequiresDaughterBoard"]?.Value ?? default(bool)),
                           SerialNumber            = (string)(managementObject.Properties["SerialNumber"]?.Value),
                           Sku                 = (string)(managementObject.Properties["SKU"]?.Value),
                           SlotLayout          = (string)(managementObject.Properties["SlotLayout"]?.Value),
                           SpecialRequirements = (bool)(managementObject.Properties["SpecialRequirements"]?.Value ?? default(bool)),
                           Status              = (string)(managementObject.Properties["Status"]?.Value),
                           Tag                 = (string)(managementObject.Properties["Tag"]?.Value),
                           Version             = (string)(managementObject.Properties["Version"]?.Value),
                           Weight              = (float)(managementObject.Properties["Weight"]?.Value ?? default(float)),
                           Width               = (float)(managementObject.Properties["Width"]?.Value ?? default(float))
                       }
            }
            ;
        }
    }
Пример #23
0
        public List<Dictionary<string, object>> GatherDeviceData(string win32class, string scope, string conditions = null, params string[] properties)
        {
            if (!properties.Any())
            {
                properties = new string[] { "*" };
            }
            var output = new List<Dictionary<string, object>>();
            var query = GetQuery(win32class, conditions, properties);

            using (var searcher = new ManagementObjectSearcher(scope, query))
            {
                var collection = searcher.Get();

                foreach (var managementObject in collection)
                {
                    var outputObject = new Dictionary<string, object>();

                    foreach (var property in properties)
                    {
                        if (outputObject.GetType().GetProperty(property).PropertyType.Name == nameof(DateTime) && managementObject[property] != null)
                        {
                            var value = ManagementDateTimeConverter
                                .ToDateTime(managementObject[property].ToString());

                            outputObject[property] = value;
                        }
                        else
                        {
                            var value = managementObject[property] is null
                                ? managementObject[property]
                                    .GetType()
                                    .GetDefault()
                                : managementObject[property];

                            outputObject[property] = value;
                        }
                    }

                    output.Add(outputObject);
                }
            }

            return output;
        }
Пример #24
0
        public override TreeNode form_output(ManagementObjectCollection collection)
        {
            int             evt_code, count = 0;
            string          time, raw, user, type;
            List <TreeNode> nodes = new List <TreeNode>();
            TreeNode        node;

            foreach (ManagementObject evt in collection)
            {
                evt_code = int.Parse(evt["EventCode"].ToString());
                switch (evt_code)
                {
                case 4625:
                    node = new TreeNode("Неудачная попытка входа");
                    time = ManagementDateTimeConverter.ToDateTime((string)evt["TimeWritten"]).ToString();
                    raw  = (string)evt["Message"];
                    user = raw.Split('\r')[12].Replace("Имя учетной записи:", "").Trim();
                    node.Nodes.Add("Пользователь: " + user);
                    node.Nodes.Add("Время: " + time);
                    nodes.Add(node);
                    count++;
                    break;

                case 4624:
                    node = new TreeNode("Удачная попытка входа");
                    time = ManagementDateTimeConverter.ToDateTime((string)evt["TimeWritten"]).ToString();
                    raw  = (string)evt["Message"];
                    type = raw.Split('\r')[8].Replace("Тип входа:", "").Trim();
                    user = raw.Split('\r')[12].Replace("Имя учетной записи:", "").Trim();
                    if (type.Equals("2"))
                    {
                        node.Nodes.Add("Пользователь: " + user);
                        node.Nodes.Add("Время: " + time);
                        nodes.Add(node);
                        count++;
                    }
                    break;
                }
            }
            TreeNode root = new TreeNode(summary + count.ToString());

            root.Nodes.AddRange(nodes.ToArray());
            return(root);
        }
Пример #25
0
        public static IEnumerable <PrintJob> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_PrintJob");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new PrintJob
                       {
                           Caption        = (string)(managementObject.Properties["Caption"]?.Value),
                           Color          = (string)(managementObject.Properties["Color"]?.Value),
                           DataType       = (string)(managementObject.Properties["DataType"]?.Value),
                           Description    = (string)(managementObject.Properties["Description"]?.Value),
                           Document       = (string)(managementObject.Properties["Document"]?.Value),
                           DriverName     = (string)(managementObject.Properties["DriverName"]?.Value),
                           ElapsedTime    = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["ElapsedTime"]?.Value as string ?? "00010102000000.000000+060"),
                           HostPrintQueue = (string)(managementObject.Properties["HostPrintQueue"]?.Value),
                           InstallDate    = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           JobId          = (uint)(managementObject.Properties["JobId"]?.Value ?? default(uint)),
                           JobStatus      = (string)(managementObject.Properties["JobStatus"]?.Value),
                           Name           = (string)(managementObject.Properties["Name"]?.Value),
                           Notify         = (string)(managementObject.Properties["Notify"]?.Value),
                           Owner          = (string)(managementObject.Properties["Owner"]?.Value),
                           PagesPrinted   = (uint)(managementObject.Properties["PagesPrinted"]?.Value ?? default(uint)),
                           PaperLength    = (uint)(managementObject.Properties["PaperLength"]?.Value ?? default(uint)),
                           PaperSize      = (string)(managementObject.Properties["PaperSize"]?.Value),
                           PaperWidth     = (uint)(managementObject.Properties["PaperWidth"]?.Value ?? default(uint)),
                           Parameters     = (string)(managementObject.Properties["Parameters"]?.Value),
                           PrintProcessor = (string)(managementObject.Properties["PrintProcessor"]?.Value),
                           Priority       = (uint)(managementObject.Properties["Priority"]?.Value ?? default(uint)),
                           Size           = (uint)(managementObject.Properties["Size"]?.Value ?? default(uint)),
                           SizeHigh       = (uint)(managementObject.Properties["SizeHigh"]?.Value ?? default(uint)),
                           StartTime      = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["StartTime"]?.Value as string ?? "00010102000000.000000+060"),
                           Status         = (string)(managementObject.Properties["Status"]?.Value),
                           StatusMask     = (uint)(managementObject.Properties["StatusMask"]?.Value ?? default(uint)),
                           TimeSubmitted  = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["TimeSubmitted"]?.Value as string ?? "00010102000000.000000+060"),
                           TotalPages     = (uint)(managementObject.Properties["TotalPages"]?.Value ?? default(uint)),
                           UntilTime      = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["UntilTime"]?.Value as string ?? "00010102000000.000000+060")
                       }
            }
            ;
        }
    }
Пример #26
0
        public void PrintSummaryInformation(
            MetroLabel CPU_Caption,
            MetroLabel CPU_Clock,
            MetroLabel CPU_Voltage,
            MetroLabel RAM_Clock,
            MetroLabel RAM_Size,
            MetroLabel MB_Caption,
            MetroLabel MB_System_Caption,
            MetroLabel MB_Manafucturer,
            MetroLabel GPU_Caption,
            MetroLabel GPU_RAM_Size,
            MetroLabel GPU_Manafacturer,
            MetroLabel OS_Cpation,
            MetroLabel OS_Architecture,
            MetroLabel OS_Build_Number,
            MetroLabel OS_Version,
            MetroLabel OS_Install_Time,
            MetroLabel OS_Last_Time_Up_Boot_Time
            )
        {
            CPU_Caption.Text = cpu.Name;
            CPU_Clock.Text   = String.Format("{0:F2} Ghz", (cpu.CurrentClock / 1000f));
            CPU_Voltage.Text = String.Format("{0:F3} V", cpu.Voltage);
            Double Pysical_Size = (ram.PysicalSize / 1024f / 1024f / 1024f);

            RAM_Clock.Text         = String.Format("{0} Mhz", ram.Speed);
            RAM_Size.Text          = String.Format("{0:F2} GB", Pysical_Size);
            MB_Caption.Text        = bios.BaseProduct;
            MB_Manafucturer.Text   = bios.BaseManufacturer;
            MB_System_Caption.Text = bios.SystemProductName;
            GPU_Caption.Text       = gpu.Caption;
            GPU_RAM_Size.Text      = String.Format("{0:F2} GB", (Convert.ToInt64(gpu.AdapterRAM) / 1024f / 1024f / 1024f));
            GPU_Manafacturer.Text  = gpu.AdapterCompatiability;
            OS_Cpation.Text        = os.Caption;
            OS_Architecture.Text   = os.Architecture;
            OS_Build_Number.Text   = os.BuildNumber;
            OS_Version.Text        = os.Version;
            DateTime time = os.InstallTime;

            OS_Install_Time.Text = time.ToString();
            DateTime time1 = ManagementDateTimeConverter.ToDateTime(os.LastBootUpTime);

            OS_Last_Time_Up_Boot_Time.Text = time1.ToString();
        }
Пример #27
0
    public static IEnumerable <ProcessCommand> FindAll()
    {
        const string?wmiQuery = @"
select CommandLine, ProcessId, CreationDate
from Win32_Process
where CommandLine like '% %.%.%'";

        using var searcher   = new ManagementObjectSearcher(wmiQuery);
        using var collection = searcher.Get();
        foreach (var process in collection)
        {
            var command            = (string)process["CommandLine"];
            var id                 = (int)Convert.ChangeType(process["ProcessId"], typeof(int));
            var creationDateString = (string)process["CreationDate"];
            var creationDate       = ManagementDateTimeConverter.ToDateTime(creationDateString);
            process.Dispose();
            yield return(new ProcessCommand(command, id, creationDate));
        }
    }
Пример #28
0
        public static IEnumerable <ShadowCopy> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_ShadowCopy");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new ShadowCopy
                       {
                           Caption          = (string)(managementObject.Properties["Caption"]?.Value),
                           ClientAccessible = (bool)(managementObject.Properties["ClientAccessible"]?.Value ?? default(bool)),
                           Count            = (uint)(managementObject.Properties["Count"]?.Value ?? default(uint)),
                           Description      = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceObject     = (string)(managementObject.Properties["DeviceObject"]?.Value),
                           Differential     = (bool)(managementObject.Properties["Differential"]?.Value ?? default(bool)),
                           ExposedLocally   = (bool)(managementObject.Properties["ExposedLocally"]?.Value ?? default(bool)),
                           ExposedName      = (string)(managementObject.Properties["ExposedName"]?.Value),
                           ExposedPath      = (string)(managementObject.Properties["ExposedPath"]?.Value),
                           ExposedRemotely  = (bool)(managementObject.Properties["ExposedRemotely"]?.Value ?? default(bool)),
                           HardwareAssisted = (bool)(managementObject.Properties["HardwareAssisted"]?.Value ?? default(bool)),
                           Id                 = (string)(managementObject.Properties["ID"]?.Value),
                           Imported           = (bool)(managementObject.Properties["Imported"]?.Value ?? default(bool)),
                           InstallDate        = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           Name               = (string)(managementObject.Properties["Name"]?.Value),
                           NoAutoRelease      = (bool)(managementObject.Properties["NoAutoRelease"]?.Value ?? default(bool)),
                           NotSurfaced        = (bool)(managementObject.Properties["NotSurfaced"]?.Value ?? default(bool)),
                           NoWriters          = (bool)(managementObject.Properties["NoWriters"]?.Value ?? default(bool)),
                           OriginatingMachine = (string)(managementObject.Properties["OriginatingMachine"]?.Value),
                           Persistent         = (bool)(managementObject.Properties["Persistent"]?.Value ?? default(bool)),
                           Plex               = (bool)(managementObject.Properties["Plex"]?.Value ?? default(bool)),
                           ProviderId         = (string)(managementObject.Properties["ProviderID"]?.Value),
                           ServiceMachine     = (string)(managementObject.Properties["ServiceMachine"]?.Value),
                           SetId              = (string)(managementObject.Properties["SetID"]?.Value),
                           State              = (uint)(managementObject.Properties["State"]?.Value ?? default(uint)),
                           Status             = (string)(managementObject.Properties["Status"]?.Value),
                           Transportable      = (bool)(managementObject.Properties["Transportable"]?.Value ?? default(bool)),
                           VolumeName         = (string)(managementObject.Properties["VolumeName"]?.Value)
                       }
            }
            ;
        }
    }
Пример #29
0
 public Win32LogicalDisk(ManagementObject mo)
 {
     Access                  = (ushort)(mo.Properties["Access"]?.Value ?? default(ushort));
     Availability            = (ushort)(mo.Properties["Availability"]?.Value ?? default(ushort));
     BlockSize               = (ulong)(mo.Properties["BlockSize"]?.Value ?? default(ulong));
     Caption                 = (string)(mo.Properties["Caption"]?.Value);
     Compressed              = (bool)(mo.Properties["Compressed"]?.Value ?? default(bool));
     ConfigManagerErrorCode  = (uint)(mo.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint));
     ConfigManagerUserConfig = (bool)(mo.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool));
     CreationClassName       = (string)(mo.Properties["CreationClassName"]?.Value);
     Description             = (string)(mo.Properties["Description"]?.Value);
     DeviceID                = (string)(mo.Properties["DeviceID"]?.Value);
     DriveType               = (uint)(mo.Properties["DriveType"]?.Value ?? default(uint));
     ErrorCleared            = (bool)(mo.Properties["ErrorCleared"]?.Value ?? default(bool));
     ErrorDescription        = (string)(mo.Properties["ErrorDescription"]?.Value);
     ErrorMethodology        = (string)(mo.Properties["ErrorMethodology"]?.Value);
     FileSystem              = (string)(mo.Properties["FileSystem"]?.Value);
     FreeSpace               = (ulong)(mo.Properties["FreeSpace"]?.Value ?? default(ulong));
     InstallDate             = ManagementDateTimeConverter.ToDateTime(mo.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060");
     LastErrorCode           = (uint)(mo.Properties["LastErrorCode"]?.Value ?? default(uint));
     MaximumComponentLength  = (uint)(mo.Properties["MaximumComponentLength"]?.Value ?? default(uint));
     MediaType               = (uint)(mo.Properties["MediaType"]?.Value ?? default(uint));
     Name           = (string)(mo.Properties["Name"]?.Value);
     NumberOfBlocks = (ulong)(mo.Properties["NumberOfBlocks"]?.Value ?? default(ulong));
     PNPDeviceID    = (string)(mo.Properties["PNPDeviceID"]?.Value);
     PowerManagementCapabilities = (ushort[])(mo.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]);
     PowerManagementSupported    = (bool)(mo.Properties["PowerManagementSupported"]?.Value ?? default(bool));
     ProviderName                 = (string)(mo.Properties["ProviderName"]?.Value);
     Purpose                      = (string)(mo.Properties["Purpose"]?.Value);
     QuotasDisabled               = (bool)(mo.Properties["QuotasDisabled"]?.Value ?? default(bool));
     QuotasIncomplete             = (bool)(mo.Properties["QuotasIncomplete"]?.Value ?? default(bool));
     QuotasRebuilding             = (bool)(mo.Properties["QuotasRebuilding"]?.Value ?? default(bool));
     Size                         = (ulong)(mo.Properties["Size"]?.Value ?? default(ulong));
     Status                       = (string)(mo.Properties["Status"]?.Value);
     StatusInfo                   = (ushort)(mo.Properties["StatusInfo"]?.Value ?? default(ushort));
     SupportsDiskQuotas           = (bool)(mo.Properties["SupportsDiskQuotas"]?.Value ?? default(bool));
     SupportsFileBasedCompression = (bool)(mo.Properties["SupportsFileBasedCompression"]?.Value ?? default(bool));
     SystemCreationClassName      = (string)(mo.Properties["SystemCreationClassName"]?.Value);
     SystemName                   = (string)(mo.Properties["SystemName"]?.Value);
     VolumeDirty                  = (bool)(mo.Properties["VolumeDirty"]?.Value ?? default(bool));
     VolumeName                   = (string)(mo.Properties["VolumeName"]?.Value);
     VolumeSerialNumber           = (string)(mo.Properties["VolumeSerialNumber"]?.Value);
 }
Пример #30
0
        public static IEnumerable <Win32DesktopMonitor> Retrieve(ManagementScope managementScope)
        {
            var objectQuery      = new ObjectQuery("SELECT * FROM Win32_DesktopMonitor");
            var objectSearcher   = new ManagementObjectSearcher(managementScope, objectQuery);
            var objectCollection = objectSearcher.Get();

            foreach (ManagementObject managementObject in objectCollection)
            {
                yield return new Win32DesktopMonitor
                       {
                           Availability            = (ushort)(managementObject.Properties["Availability"]?.Value ?? default(ushort)),
                           Bandwidth               = (uint)(managementObject.Properties["Bandwidth"]?.Value ?? default(uint)),
                           Caption                 = (string)(managementObject.Properties["Caption"]?.Value),
                           ConfigManagerErrorCode  = (uint)(managementObject.Properties["ConfigManagerErrorCode"]?.Value ?? default(uint)),
                           ConfigManagerUserConfig = (bool)(managementObject.Properties["ConfigManagerUserConfig"]?.Value ?? default(bool)),
                           CreationClassName       = (string)(managementObject.Properties["CreationClassName"]?.Value),
                           Description             = (string)(managementObject.Properties["Description"]?.Value),
                           DeviceId                = (string)(managementObject.Properties["DeviceID"]?.Value),
                           DisplayType             = (ushort)(managementObject.Properties["DisplayType"]?.Value ?? default(ushort)),
                           ErrorCleared            = (bool)(managementObject.Properties["ErrorCleared"]?.Value ?? default(bool)),
                           ErrorDescription        = (string)(managementObject.Properties["ErrorDescription"]?.Value),
                           InstallDate             = ManagementDateTimeConverter.ToDateTime(managementObject.Properties["InstallDate"]?.Value as string ?? "00010102000000.000000+060"),
                           IsLocked                = (bool)(managementObject.Properties["IsLocked"]?.Value ?? default(bool)),
                           LastErrorCode           = (uint)(managementObject.Properties["LastErrorCode"]?.Value ?? default(uint)),
                           MonitorManufacturer     = (string)(managementObject.Properties["MonitorManufacturer"]?.Value),
                           MonitorType             = (string)(managementObject.Properties["MonitorType"]?.Value),
                           Name = (string)(managementObject.Properties["Name"]?.Value),
                           PixelsPerXLogicalInch       = (uint)(managementObject.Properties["PixelsPerXLogicalInch"]?.Value ?? default(uint)),
                           PixelsPerYLogicalInch       = (uint)(managementObject.Properties["PixelsPerYLogicalInch"]?.Value ?? default(uint)),
                           PnpDeviceId                 = (string)(managementObject.Properties["PNPDeviceID"]?.Value),
                           PowerManagementCapabilities = (ushort[])(managementObject.Properties["PowerManagementCapabilities"]?.Value ?? new ushort[0]),
                           PowerManagementSupported    = (bool)(managementObject.Properties["PowerManagementSupported"]?.Value ?? default(bool)),
                           ScreenHeight                = (uint)(managementObject.Properties["ScreenHeight"]?.Value ?? default(uint)),
                           ScreenWidth                 = (uint)(managementObject.Properties["ScreenWidth"]?.Value ?? default(uint)),
                           Status     = (string)(managementObject.Properties["Status"]?.Value),
                           StatusInfo = (ushort)(managementObject.Properties["StatusInfo"]?.Value ?? default(ushort)),
                           SystemCreationClassName = (string)(managementObject.Properties["SystemCreationClassName"]?.Value),
                           SystemName = (string)(managementObject.Properties["SystemName"]?.Value)
                       }
            }
            ;
        }
    }