http://msdn.microsoft.com/en-us/library/ms229660.aspx
1 public class PlatformDetector
2 {
3 [DllImport("coredll.dll")]
4 private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
5
6 private static uint SPI_GETPLATFORMTYPE = 257;
7
8 public static Platform GetPlatform()
9 {
10 Platform plat = Platform.Unknown;
11 switch (System.Environment.OSVersion.Platform)
12 {
13 case PlatformID.Win32NT:
14 plat = Platform.Win32NT;
15 break;
16 case PlatformID.Win32S:
17 plat = Platform.Win32S;
18 break;
19 case PlatformID.Win32Windows:
20 plat = Platform.Win32Windows;
21 break;
22 case PlatformID.WinCE:
23 plat = CheckWinCEPlatform();
24 break;
25 }
26
27 return plat;
28 }
29
30 static Platform CheckWinCEPlatform()
31 {
32 Platform plat = Platform.WindowsCE;
33 StringBuilder strbuild = new StringBuilder(200);
34 SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0);
35 string str = strbuild.ToString();
36 switch (str)
37 {
38 case "PocketPC":
39 plat = Platform.PocketPC;
40 break;
41 case "SmartPhone":
42 // Note that the strbuild parameter from the
43 // PInvoke returns "SmartPhone" with an
44 // upper case P. The correct casing is
45 // "Smartphone" with a lower case p.
46 plat = Platform.Smartphone;
47 break;
48 }
49 return plat;
50 }
51 }
52
53 public enum Platform
54 {
55 PocketPC, WindowsCE, Smartphone, Win32NT, Win32S, Win32Windows, Unknown
2 {
3 [DllImport("coredll.dll")]
4 private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
5
6 private static uint SPI_GETPLATFORMTYPE = 257;
7
8 public static Platform GetPlatform()
9 {
10 Platform plat = Platform.Unknown;
11 switch (System.Environment.OSVersion.Platform)
12 {
13 case PlatformID.Win32NT:
14 plat = Platform.Win32NT;
15 break;
16 case PlatformID.Win32S:
17 plat = Platform.Win32S;
18 break;
19 case PlatformID.Win32Windows:
20 plat = Platform.Win32Windows;
21 break;
22 case PlatformID.WinCE:
23 plat = CheckWinCEPlatform();
24 break;
25 }
26
27 return plat;
28 }
29
30 static Platform CheckWinCEPlatform()
31 {
32 Platform plat = Platform.WindowsCE;
33 StringBuilder strbuild = new StringBuilder(200);
34 SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0);
35 string str = strbuild.ToString();
36 switch (str)
37 {
38 case "PocketPC":
39 plat = Platform.PocketPC;
40 break;
41 case "SmartPhone":
42 // Note that the strbuild parameter from the
43 // PInvoke returns "SmartPhone" with an
44 // upper case P. The correct casing is
45 // "Smartphone" with a lower case p.
46 plat = Platform.Smartphone;
47 break;
48 }
49 return plat;
50 }
51 }
52
53 public enum Platform
54 {
55 PocketPC, WindowsCE, Smartphone, Win32NT, Win32S, Win32Windows, Unknown
56 }
[DllImport("coredll.dll", SetLastError = true)]
private static extern bool KernelIoControl(Int32 dwIoControlCode,
IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf,
Int32 nOutBufSize, ref Int32 lpBytesReturned);
private void DeviceType_Load(object sender, System.EventArgs e)
{
try
{
MessageBox.Show("Platform is " + PlatformDetector.GetPlatform());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
private static extern bool KernelIoControl(Int32 dwIoControlCode,
IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf,
Int32 nOutBufSize, ref Int32 lpBytesReturned);
private void DeviceType_Load(object sender, System.EventArgs e)
{
try
{
MessageBox.Show("Platform is " + PlatformDetector.GetPlatform());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}