Address: http://blogs.msdn.com/ B /netcfteam/archive/2006/09/15/756755.aspx
Code As follows:
Using System;
Using System. IO;
Using System. Windows. forms;
Using Microsoft. Win32;
Using System. runtime. interopservices;
Using System. text;
Namespace Platformdetection
{
Internal Partial Class Pinvoke
{
[Dllimport ( " Coredll. dll " , Entrypoint = " Systemparametersinfow " , Charset = Charset. Unicode)]
Static Extern Int Systemparametersinfo4strings ( Uint Uiaction, Uint Uiparam, stringbuilder pvparam, Uint Fwinini );
Public Enum Systemparametersinfoactions: Uint
{
Spi_getplatformtype = 257 , // This is used elsewhere for smartphone/pocketpc Detection
Spi_getoeminfo = 258 ,
}
Public Static String Getoeminfo ()
{
Stringbuilder oeminfo = New Stringbuilder ( 50 );
If (Systemparametersinfo4strings (( Uint ) Systemparametersinfoactions. spi_getoeminfo,
( Uint ) Oeminfo. Capacity, oeminfo, 0 ) = 0 )
Throw New Exception ( " Error getting OEM info. " );
Return Oeminfo. tostring ();
}
}
Internal Partial Class Platformdetection
{
Private Const String Microsoftemulatoroemvalue = " Microsoft deviceemulator " ;
Public Static Bool Isemulator ()
{
Return Pinvoke. getoeminfo () = Microsoftemulatoroemvalue;
}
}
Class Emulatorprogram
{
Static Void Main ( String [] ARGs)
{
MessageBox. Show ( " Emulator: " + (Platformdetection. isemulator () ? " Yes " : " No " ));
}
}
}