Answered by:
Can I use Windows.Devices.Enumeration namespace in non-metro/desktop app?

Question
-
What if I need to support the devices from desktop also, can I use the WRT api? If not, what is the equivalent functions of Windows.Devices.Enumeration ? Maybe .NET 4.5??
Lee
Tuesday, October 11, 2011 2:47 AM
Answers
-
To follow up on this, Windows.Devices.Enumeration can be called from Desktop apps. You will need to add references to the %windir%\system32\WinMetaData\Windows.Foundation.winmd and Windows.Devices.Enumaration.windmd files from and the System.Runtime.WindowsRuntime assembly from %windir%\Microsoft.Net and then you'll be able to call into Windows.Devices.Enumeration from a Desktop .Net application.
Here's a simple demo console app:
using System; using System.Threading.Tasks; using Windows.Devices.Enumeration; namespace DeviceEnumerationConsoleTest { class Program { static void Main(string[] args) { EnumerateDevices().Wait(); } static async Task EnumerateDevices() { DeviceInformationCollection dic = await DeviceInformation.FindAllAsync(); foreach (DeviceInformation di in dic) { Console.WriteLine(di.Name + " : " + di.Id); } } } }
--Rob
- Proposed as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, October 26, 2011 8:51 PM
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, November 2, 2011 7:25 AM
Tuesday, October 25, 2011 5:53 PMModerator
All replies
-
Different types of devices will be approached through different API on the desktop. Which API to call will depend on the context from which you are calling it and which devices you are interested in. You'll find people with better familiarity with the details if you ask in the appropriate forum for the API set you are using and are specific about which devices you want to interact with.
--Rob
Thursday, October 13, 2011 2:14 AMModerator -
To follow up on this, Windows.Devices.Enumeration can be called from Desktop apps. You will need to add references to the %windir%\system32\WinMetaData\Windows.Foundation.winmd and Windows.Devices.Enumaration.windmd files from and the System.Runtime.WindowsRuntime assembly from %windir%\Microsoft.Net and then you'll be able to call into Windows.Devices.Enumeration from a Desktop .Net application.
Here's a simple demo console app:
using System; using System.Threading.Tasks; using Windows.Devices.Enumeration; namespace DeviceEnumerationConsoleTest { class Program { static void Main(string[] args) { EnumerateDevices().Wait(); } static async Task EnumerateDevices() { DeviceInformationCollection dic = await DeviceInformation.FindAllAsync(); foreach (DeviceInformation di in dic) { Console.WriteLine(di.Name + " : " + di.Id); } } } }
--Rob
- Proposed as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, October 26, 2011 8:51 PM
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Wednesday, November 2, 2011 7:25 AM
Tuesday, October 25, 2011 5:53 PMModerator