private static PnpObject GetHalDevice(params String[] properties) { String[] strArray = properties; String[] strArray1 = { "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10" }; IEnumerable <String> enumerable = strArray.Concat(strArray1); try { PnpObjectCollection pnpObjectCollection = PnpObject.FindAllAsync(PnpObjectType.Device, enumerable, "System.Devices.ContainerId:=\"{00000000-0000-0000-FFFF-FFFFFFFFFFFF}\"").GetResults(); foreach (PnpObject pnpObject in pnpObjectCollection) { if (pnpObject.Properties == null || !pnpObject.Properties.Any()) { continue; } KeyValuePair <String, Object> keyValuePair = pnpObject.Properties.Last(); if (keyValuePair.Value == null || !keyValuePair.Value.ToString().Equals("4d36e966-e325-11ce-bfc1-08002be10318")) { continue; } return(pnpObject); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception: " + e.Message); return(null); } return(null); }
/// <summary> /// Attempt to find the HAL (Hardware Abstraction Layer) device for this computer. /// </summary> /// <param name="properties">Additional property names to obtain for the HAL.</param> /// <returns>PnpObject of the HAL with the additional properties populated.</returns> private static async Task <PnpObject> GetHalDevice(params string[] properties) { var actualProperties = properties.Concat(new[] { DeviceClassKey, DeviceDriverProviderKey }); var rootDevices = (await PnpObject.FindAllAsync(PnpObjectType.Device, actualProperties, RootContainerQuery)); return(rootDevices.FirstOrDefault(rootDevice => IsMicrosoftHal(rootDevice.Properties))); }
internal static async Task <string> GetOperatingSystemVersionAsync() { if (_operatingSystemVersion == null) { try { // There is no good place to get this so we're going to use the most popular // Microsoft driver version number from the device tree. var requestedProperties = new[] { DeviceDriverVersionKey, DeviceDriverProviderKey }; var microsoftVersionedDevices = (await PnpObject.FindAllAsync(PnpObjectType.Device, requestedProperties, RootQuery)) .Select(d => new { Provider = (string)d.Properties.GetValueOrDefault(DeviceDriverProviderKey), Version = (string)d.Properties.GetValueOrDefault(DeviceDriverVersionKey) }) .Where(d => d.Provider == "Microsoft" && d.Version != null) .ToList(); var versionNumbers = microsoftVersionedDevices .GroupBy(d => d.Version.Substring(0, d.Version.IndexOf('.', d.Version.IndexOf('.') + 1))) .OrderByDescending(d => d.Count()) .ToList(); var confidence = (versionNumbers[0].Count() * 100 / microsoftVersionedDevices.Count); _operatingSystemVersion = versionNumbers.Count > 0 ? versionNumbers[0].Key : ""; } catch { _operatingSystemVersion = "Unknown"; } } return(_operatingSystemVersion); }
/// <summary> /// Device Containerを列挙する. /// </summary> /// <returns>列挙されたDevice Containerを返す</returns> private static async Task <Dictionary <Guid, PnpObject> > GetDeviceContainers() { var props = new string[] { DevicePropertyHelper.SystemItemNameDisplay, DevicePropertyHelper.SystemDevicesFriendlyName, DevicePropertyHelper.SystemDevicesModelName, DevicePropertyHelper.SystemDevicesManufacturer, DevicePropertyHelper.SystemDevicesInLocalMachineContainer, DevicePropertyHelper.SystemDevicesDiscoveryMethod, DevicePropertyHelper.SystemDevicesConnected, DevicePropertyHelper.SystemDevicesIsNetworkConnected, DevicePropertyHelper.DEVPKEY_DeviceContainer_Category, DevicePropertyHelper.DEVPKEY_DeviceContainer_PrimaryCategory, }; var devContainers = await PnpObject.FindAllAsync(PnpObjectType.DeviceContainer, props); var idContainerDict = new Dictionary <Guid, PnpObject>(devContainers.Count); foreach (var container in devContainers) { var guid = Guid.Parse(container.Id); idContainerDict.Add(guid, container); } return(idContainerDict); }
private async Task <PnpObjectCollection> GetDevices() { string[] properties = { "System.ItemNameDisplay", "System.Devices.ContainerId" }; return(await PnpObject.FindAllAsync(PnpObjectType.Device, properties)); }
public async Task <List <PnpDevice> > FindAllAsync(PnpObjectType type, IEnumerable <string> requestedProperties, string aqsFilter) { var pnpObjects = await PnpObject.FindAllAsync(type, requestedProperties, aqsFilter); var list = new List <PnpDevice>(); foreach (var pnpObject in pnpObjects) { list.Add ( new PnpDevice(pnpObject.Id, pnpObject.Properties, pnpObject.Type) ); } return(list); }
private static async Task <PnpObject> GetHalDevice(params string[] properties) { var actualProperties = properties.Concat(new[] { DeviceClassKey }); var rootDevices = await PnpObject.FindAllAsync(PnpObjectType.Device, actualProperties, RootQuery); foreach (var rootDevice in rootDevices.Where(d => d.Properties != null && d.Properties.Any())) { var lastProperty = rootDevice.Properties.Last(); if (lastProperty.Value != null) { if (lastProperty.Value.ToString().Equals(HalDeviceClass)) { return(rootDevice); } } } return(null); }
/// <summary> /// Get the version of Windows for this computer. /// </summary> /// <example>6.2</example> /// <returns>Version number of Windows running on this computer.</returns> public static async Task <string> GetWindowsVersionAsync() { // There is no good place to get this so we're going to use the most popular // Microsoft driver version number from the device tree. var requestedProperties = new[] { DeviceDriverVersionKey, DeviceDriverProviderKey }; var microsoftVersionedDevices = (await PnpObject.FindAllAsync(PnpObjectType.Device, requestedProperties, RootContainerQuery)) .Select(d => new { Provider = (string)d.Properties.GetValueOrDefault(DeviceDriverProviderKey), Version = (string)d.Properties.GetValueOrDefault(DeviceDriverVersionKey) }) .Where(d => d.Provider == "Microsoft" && d.Version != null) .ToList(); var versionNumbers = microsoftVersionedDevices .GroupBy(d => d.Version.Substring(0, d.Version.IndexOf('.', d.Version.IndexOf('.') + 1))) .OrderByDescending(d => d.Count()) .ToList(); return(versionNumbers.Count > 0 ? versionNumbers[0].Key : ""); }
async void EnumerateDeviceContainers(object sender, RoutedEventArgs eventArgs) { FocusState focusState = EnumerateContainersButton.FocusState; EnumerateContainersButton.IsEnabled = false; string[] properties = { "System.ItemNameDisplay", "System.Devices.ModelName", "System.Devices.Connected" }; var containers = await PnpObject.FindAllAsync(PnpObjectType.DeviceContainer, properties); DeviceContainersOutputList.Items.Clear(); rootPage.NotifyUser(containers.Count + " device container(s) found", NotifyType.StatusMessage); foreach (PnpObject container in containers) { DeviceContainersOutputList.Items.Add(new DisplayItem(container)); } EnumerateContainersButton.IsEnabled = true; EnumerateContainersButton.Focus(focusState); }
public static async Task <List <PnpDev> > GetPnpDevices(string deviceName) { var devices = new List <PnpDev>(); var list = await DeviceInformation.FindAllAsync("", new List <string>()); var reqs = new List <string> { PKEY_PNPX_IpAddress, PKEY_PNPX_PhysicalAddress }; foreach (var dev in list) { string name = dev.Name; if (/*dev.IsEnabled &&*/ dev.Name.Contains(deviceName, StringComparison.OrdinalIgnoreCase)) { var guid = dev.Properties["System.Devices.DeviceInstanceId"]; var aqs = "System.Devices.DeviceInstanceId:=\"" + guid + "\""; var list2 = await PnpObject.FindAllAsync(PnpObjectType.Device, reqs, aqs); foreach (var dev2 in list2) { var ipAddress = GetDeviceProperty(dev2, "System.Devices.IpAddress"); var macAddress = GetDeviceProperty(dev2, PKEY_PNPX_PhysicalAddress); if (!devices.Any(x => x.Name.Equals(name) && x.IpAddress != null && x.IpAddress.Equals(ipAddress))) { var device = new PnpDev(dev, dev2, name, ipAddress, macAddress); devices.Add(device); } } } } return(devices); }
private static async Task <PnpObject> GetHalDevice(params string[] properties) { const string DeviceClassKey = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10"; const string RootContainer = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"; const string RootQuery = "System.Devices.ContainerId:=\"" + RootContainer + "\""; const string HalDeviceClass = "4d36e966-e325-11ce-bfc1-08002be10318"; var actualProperties = properties.Concat(new[] { DeviceClassKey }); var rootDevices = await PnpObject.FindAllAsync(PnpObjectType.Device, actualProperties, RootQuery); foreach (var rootDevice in rootDevices.Where(d => d.Properties != null && d.Properties.Any())) { var lastProperty = rootDevice.Properties.Last(); if (lastProperty.Value != null) { if (lastProperty.Value.ToString().Equals(HalDeviceClass)) { return(rootDevice); } } } return(null); }
private static async Task <string> GetOsVersionUsingPnpObject() { string[] requestedProperties = new string[] { DeviceDriverVersionKey, DeviceDriverProviderKey }; PnpObjectCollection pnpObjects = await PnpObject.FindAllAsync(PnpObjectType.Device, requestedProperties, RootContainerQuery); string guessedVersion = pnpObjects.Select(item => new ProviderVersionPair { Provider = (string)GetValueOrDefault(item.Properties, DeviceDriverProviderKey), Version = (string)GetValueOrDefault(item.Properties, DeviceDriverVersionKey) }) .Where(item => string.IsNullOrEmpty(item.Version) == false) .Where(item => string.Compare(item.Provider, "Microsoft", StringComparison.Ordinal) == 0) .GroupBy(item => item.Version) .OrderByDescending(item => item.Count()) .Select(item => item.Key) .First(); return(guessedVersion); }
/// <summary> /// hdt /// </summary> /// <param name="properties"></param> /// <returns></returns> static Task <PnpObject> GetHalDevice(params string[] properties) { PnpObject result = null; var actualProperties = Enumerable.Concat <string>(properties, new string[] { "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10" }); PnpObjectCollection objects = WindowsRuntimeSystemExtensions.GetAwaiter <PnpObjectCollection>(PnpObject.FindAllAsync(PnpObjectType.Device, actualProperties, "System.Devices.ContainerId:=\"{00000000-0000-0000-FFFF-FFFFFFFFFFFF}\"")).GetResult(); foreach (PnpObject obj in objects) { KeyValuePair <string, object> pair = Enumerable.Last <KeyValuePair <string, object> >((IEnumerable <KeyValuePair <string, object> >)obj.Properties); if ((pair.Value != null) && pair.Value.ToString().Equals("4d36e966-e325-11ce-bfc1-08002be10318")) { result = obj; break; } } return(Task.FromResult <PnpObject>(result)); }