[更正]谈获取当前系统类型(SP OR PPC)

更正一下,以前没发现原来要获取平台类型不用读取注册表那么麻烦的,有一个API可以利用很简单就得到了,并且绝对准确!

函数功能描述:查询或设置系统级参数。该函数也可以在设置参数中更新用户配置文件。
函数原型:B00L SystemParametersinfo(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinlni);

实现代码

TCHAR platform[255];
    SystemParametersInfo(SPI_GETPLATFORMTYPE,
255,platform,NULL);
    
if(StringEqual(platform, TEXT("SmartPhone")))
    {
        
//SP
    }
    
else if(StringEqual(platform, TEXT("PocketPC")))
    {
        
//PPC
    }

-----------------------------------------------------------------------------------------------------------

有时候在程序中须要获得当前系统是SP还是PPC,GOOGLE了好半天也没找到相关的方法,于是想到了从注册表下手!!

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
"UA-Platform"="Pocket PC"

UA-Platform此值表示当前平台类型,如果是PPC其值是:Pocket PC,如是SP其值是:SmartPhone

这种方法不算是绝对准确,因为注册表值可以修改,不过大多数情况下这种方法还是准确的吧。

不知道大家有没有更好的办法!!

以下为读取代码。。。

static int _systemType = -1;
        
/// <summary>
        
/// 获得当前系统平台(1,SP 2,PPC 3,Undefine)
        
/// </summary>

        static int SystemType
        
{
            
get
            
{
                
if (_systemType != -1return _systemType; //-1表示未初始化

                
string platform = null;
                RegistryKey keyIE_Main 
= null;
                
try
                
{
                    keyIE_Main 
= Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main");
                    platform 
= keyIE_Main.GetValue("UA-Platform""").ToString().ToLower();
                }

                
catch { }
                
finally
                
{
                    
if (keyIE_Main != null) keyIE_Main.Close();
                }

                
if (platform == null)
                
{
                    
//读取失败本次将不在读取,置为未定义
                    _systemType = 3;
                    
return _systemType;
                }


                 
                
if (platform == "smartphone")
                
{
                    _systemType 
= 1;
                }

                
else if (platform == "pocket pc")
                
{
                    _systemType 
= 2;
                }

                
else
                
{
                    _systemType 
= 3;
                }

                
return _systemType;
            }

        }
原文地址:https://www.cnblogs.com/mondol/p/1331204.html