【问题标题】:Getting OS, Platform and Device information on Windows 8在 Windows 8 上获取操作系统、平台和设备信息
【发布时间】:2013-09-07 02:51:52
【问题描述】:

如何在 Windows 8 上获取以下信息?

平台、操作系统版本、设备名称、设备 ID 和运营商(不确定运营商是否适用于 Windows 8)

在 Windows Phone 8 中,我使用以下方法检索它们:

Platform: Environment.OSVersion.Platform
OS Version: Environment.OSVersion.Version
Device name: Microsoft.Phone.Info.DeviceStatus.DeviceName
Device ID: Windows.Phone.System.Analytics.HostInformation.PublisherHostId
Carrier: Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator

我正在使用 C# 寻找与上述 Windows Phone 8 信息等效的 Windows 8。

【问题讨论】:

  • 桌面或 Windows 应用商店应用?
  • 好问题,它是 Windows 应用商店。
  • OSversion = "windows 8" ;-)
  • 仅供参考:Microsoft.Phone.Info.DeviceStatus.DeviceName 电话在我的通用应用项目中似乎不可用

标签: c# windows-8 windows-runtime microsoft-metro windows-store-apps


【解决方案1】:

您可以从here获取以下信息

  • Windows 版本

  • 处理器架构

  • 设备类别

  • 设备制造商

  • 设备型号

有关唯一 ID,请参阅 UDID for windows 8

您可以从here获取以下信息

  • 应用版本

  • 操作系统版本

  • 机器名称

【讨论】:

  • attackpattern 中的代码对于 XAML 应用程序是不可编译的。自动/等待是非法的。
  • attachpattern 中的代码缺少返回类型。用可行的代码查看我的更新答案。
  • 从某处复制代码并剥离出处和版权声明是蹩脚的。
  • 我没有复制。我发布代码是因为参考站点可能会关闭。那么网站就没有意义了。虽然添加了版权声明。
  • 我找到了攻击模式代码的副本。答案已更新。您可以查看here
【解决方案2】:

我只有 ItemNameKey、ModelNameKey、ManufacturerKey,或者没有十六进制数字的那些。其他人没有,不知道为什么。这是工作代码,但在 C++ 中,由于在 C++/CX 中没有任何问题,我将其发布在这里(花了一段时间才弄清楚 C# 中使用了哪些命名空间,并且花了大约一个小时来弄清楚如何用 C++ 编写任何可派生的东西并处理 Collections::Iterable 和 Collections::Iterator)

using namespace Windows::System;
//using namespace Windows::System::L.Linq;
using namespace Windows::System::Threading;
using namespace Windows::Devices::Enumeration::Pnp;
 using namespace Collections;
//public class SystemInfoEstimate
//{

Platform::Array< Platform::String ^> ^StrArray;// = ref new Platform::Array< Platform::String ^>(1);

ref class MyIterator sealed: IIterator<Platform::String ^>
{
    int Index;
    public:
    MyIterator()
    {
        Index = 0;
    }


    property virtual Platform::String ^ Current 
    { 
       Platform::String ^ get()
       {
           return StrArray->get( Index );
       }
    }   
    property virtual bool HasCurrent 
    { 
       bool get()
       {
           return true;
       }
    }
    virtual bool MoveNext()
    {
        Index++;
        if (Index >=StrArray->Length)
            return false;
        return true;
    }
    virtual unsigned int GetMany( Platform::WriteOnlyArray<Platform::String ^> ^Arr)
    {
        for(int i=0; i<StrArray->Length; i++)
        {           
            Arr->set( i, StrArray[i] );
        }
        return StrArray->Length;
    }
};
ref class MyIterable sealed: IIterable<Platform::String ^>
{
public:
    virtual IIterator<Platform::String ^> ^First()
    {
        return ref new MyIterator();//StrArray[0];
    }
};

    Platform::String ^ItemNameKey = "System.ItemNameDisplay";
    Platform::String ^ ModelNameKey = "System.Devices.ModelName";
    Platform::String ^ ManufacturerKey = "System.Devices.Manufacturer";
    Platform::String ^ DeviceClassKey = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10";
    Platform::String ^ PrimaryCategoryKey = "{78C34FC8-104A-4ACA-9EA4-524D52996E57},97";
    Platform::String ^ DeviceDriverVersionKey = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3";
    Platform::String ^ RootContainer = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}";
    Platform::String ^ RootQuery = "System.Devices.ContainerId:=\"" + RootContainer + "\"";
    Platform::String ^ HalDeviceClass = "4d36e966-e325-11ce-bfc1-08002be10318";

void GetSystemInfo()
{
    //return;
    StrArray = ref new Platform::Array< Platform::String ^>(2);
    MyIterable^ MI = ref new MyIterable();
    StrArray->set( 0, ModelNameKey );//ManufacturerKey );
    StrArray->set( 1, ManufacturerKey );
    auto v = create_task( PnpObject::CreateFromIdAsync(PnpObjectType::DeviceContainer, RootContainer, MI )//StrArray);
        );
    v.wait();
    PnpObject ^Ret = v.get();
    UINT Size = Ret->Properties->Size;
    if (Size > 0)
    {
        for(int i=0; i<StrArray->Length; i++)
        {
            IIterator< IKeyValuePair< Platform::String ^, Platform::Object ^>^ > ^ It = Ret->Properties->First();

            bool Moving = true;
            while(Moving)
            {
                Platform::String ^PropStr = It->Current->Value->ToString();
                            //You could put OutputDebugString here ^
                Moving = It->MoveNext();
            }            
        }
    }    
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-09
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 2021-03-07
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多