Пример #1
0
        /// <summary>
        /// Get the class Guid of a VideoDevice.
        /// </summary>
        /// <param name="device">The VideoDevice object to get the class guid.</param>
        /// <returns>Returns a string that indicates the class guid of the device.</returns>
        public static string GetDeviceClassGuid(VideoDevice device)
        {
            if (string.IsNullOrEmpty(device.Name) || string.IsNullOrEmpty(device.DeviceId))
                throw new ArgumentException("Device Name and device Id can't be set to nothing.");

            string queryString = string.Format("SELECT * FROM Win32_PnPSignedDriver WHERE DeviceName='{0}' AND DeviceID='{1}'", device.Name, device.PnpDeviceId.Replace(@"\", @"\\"));
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", queryString))
            {
                ManagementObject queryObj = searcher.Get().OfType<ManagementObject>().FirstOrDefault();
                return queryObj == null ? null : (string)queryObj["ClassGuid"];
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieve all the video controllers currently active on the system.
        /// </summary>
        /// <returns>Returns a VideoDevice list that contains all the devices that are currently active.</returns>
        public static List<VideoDevice> GetPrimaryDevices()
        {
            List<VideoDevice> devices = new List<VideoDevice>();

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController"))
            {
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    // The name of the device.
                    string name = (string)queryObj["Name"];
                    // The description of the device.
                    string description = (string)queryObj["Description"];
                    // The amount of ram available on the device.
                    int ram = Convert.ToInt32(queryObj["AdapterRAM"]);
                    // The ID of the device.
                    string deviceId = (string)queryObj["DeviceID"];
                    // The PnP ID of the device.
                    string pnpDeviceId = (string)queryObj["PNPDeviceID"];
                    // The current status of the device.
                    string status = (string)queryObj["Status"];
                    // The processor information of the device.
                    string processorInfo = (string)queryObj["VideoProcessor"];

                    VideoDevice device = new VideoDevice(name);
                    device.Description = description;
                    device.RAM = ram;
                    device.DeviceId = deviceId;
                    device.PnpDeviceId = pnpDeviceId;
                    device.ProcessorInformation = processorInfo;
                    device.Status = status;
                    device.ClassGuid = GetDeviceClassGuid(device);

                    devices.Add(device);
                }
            }

            return devices;
        }