Note that the source code must be referenced by the user: Microsoft. smartdevice. Connectivity. dll
For the Windows Phone 7 SDK after the correct installation, the platform and device queried in the datastoremanager type should be like this.
=== Platform ===
Windows Phone 7
=== Device ===
Windows Phone Device
Windows Phone emulator-512 MB
Windows Phone emulator-256 MB
The Code is as follows:
// + Using Microsoft. smartdevice. connectivity;
VaR Mgr = new datastoremanager (system. Globalization. cultureinfo. currentculture. lcid );
Console. writeline ("=== platform === ");
Foreach (VAR platform in Mgr. getplatforms ())
{
Console. writeline (platform. Name );
Console. writeline ("=== device === ");
Foreach (VAR device in platform. getdevices ())
Console. writeline (device. Name );
}
The device can be activated through the device. Activate method, but only if the device has been connected and the connection can be through the connect method. For example, if we want to activate a MB simulator, the Code is as follows:
// + Using Microsoft. smartdevice. connectivity;
VaR Mgr = new datastoremanager (system. Globalization. cultureinfo. currentculture. lcid );
Foreach (VAR platform in Mgr. getplatforms ())
{
Foreach (VAR device in platform. getdevices ())
{
Try
{
// Search for the 512 characters in the name
If (device. Name. Contains ("512 "))
{
// Connection
Device. Connect ();
// Activate
Device. Activate ();
}
}
Catch (exception E)
{
Console. writeline (E );
}
}
}
OK. After the program is run, the corresponding Windows Phone simulator will run:
In addition, the device. isenumator method can be used to determine whether the target device is a simulator.
You can use the device. getsysteminfo method to query any device information, including the simulator and the actual device. Getsysteminfo returns a systeminfo object containing multiple options.
Sit down with your phone and test. First connect your phone to your computer, and then start Zune. Call device. Connect and getsysteminfo.
Complete code:
// + Using Microsoft. smartdevice. connectivity;
// + Using system. componentmodel; used to quickly output all attributes
Static void main (string [] ARGs)
{
VaR Mgr = new datastoremanager (system. Globalization. cultureinfo. currentculture. lcid );
Foreach (VAR platform in Mgr. getplatforms ())
{
Foreach (VAR device in platform. getdevices ())
{
Try
{
// Windows Phone device is required, which indicates the actual device connected
If (device. Name. Contains ("device "))
{
// Connection
Device. Connect ();
// Activate
Device. Activate ();
// Output information
Printproperties (device. getsysteminfo ());
}
}
Catch (exception E)
{
Console. writeline (E );
}
}
}
}
// Quickly output all attributes
Static void printproperties (Object OBJ)
{
Foreach (propertydescriptor descriptor in typedescriptor. getproperties (OBJ ))
{
String name = descriptor. Name;
Object value = descriptor. getvalue (OBJ );
Console. writeline ("{0 }:{ 1}", name, value );
}
}
OK, and the result will be output:
Osmajor: 7
Osminor: 10
Osbuildno: 8107
Processorarchitecture: Arm
Instructionset: armv4ifp
Numberofprocessors: 1
......
A lot of information, such as operating system version: 7.10.8107, processor type: arm, instruction set: armv4ifp ......