简体   繁体   English

在Windows 8上获取操作系统,平台和设备信息

[英]Getting OS, Platform and Device information on Windows 8

How do I get the following information on Windows 8? 如何在Windows 8上获取以下信息?

Platform, OS version, device name, device ID and carrier (not sure if carrier is applicable to Windows 8) 平台,操作系统版本,设备名称,设备ID和运营商(不确定运营商是否适用于Windows 8)

With Windows Phone 8, I retrieve them using: 使用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

I am looking for the Windows 8 equivalent of the above Windows Phone 8 information using C#. 我正在寻找使用C#的Windows 8等效的上述Windows Phone 8信息。

You can get below information from here 您可以从这里获得以下信息

  • Windows Version Windows版本

  • Processor Architecture 处理器架构

  • Device Category 设备类别

  • Device Manufacturer 设备制造商

  • Device Model 设备模型

For unique ID, see UDID for windows 8 有关唯一ID,请参阅Windows 8的UDID

You can get below information from here 您可以从这里获得以下信息

  • App Version 应用版本

  • OS Version 操作系统版本

  • Machine Name 机器名称

I only got ItemNameKey, ModelNameKey, ManufacturerKey, to work or the ones without hex numbers. 我只使用ItemNameKey,ModelNameKey,ManufacturerKey工作或没有十六进制数字的工作。 The others don't, dunno why. 其他人没有,不知道为什么。 This is working code but in C++, and since there's nothing on the matter in C++/CX, I'm posting it here (took a while to figure out even what namespaces are used in C# and took about an hour to figure out how to write anything derivable & working off Collections::Iterable and Collections::Iterator in C++) 这是工作代码但是在C ++中,因为C ++ / CX中没有任何内容,我在这里发布它(花了一些时间来弄清楚C#中使用了哪些命名空间,花了大约一个小时来弄清楚如何写任何可派生的和工作的集合:: Iterable和Collections :: Iterator in C ++)

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();
            }            
        }
    }    
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM