如何在Windows10Universal中获取设备的唯一标识符?这是我为WindowsUniversal8.1获取唯一DeviceID的旧实现,但类型HardwareIdentification不再存在。私有静态字符串GetId(){vartoken=HardwareIdentification.GetPackageSpecificToken(null);varhardwareId=token.Id;vardataReader=Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);byte[]bytes=newbyte[hardwareId.Length];dataReader.ReadBytes(字节);返回BitConverter.ToString(bytes).Replace("-","");这是Windows桌面的完整解决方案:使用此代码获取HardwareId:usingSystem;使用Windows.Security.ExchangeActiveSyncProvisioning;使用Windows.System.Profile;namespaceTobit.Software.Device{publicsealedclassDeviceInfo{privatestaticDeviceInfo_Instance;publicstaticDeviceInfoInstance{get{if(_Instance==null)_Instance=newDeviceInfo();返回_实例;}}公共字符串ID{得到;私有集;}公共字符串模型{得到;私有集;}公共字符串制造商{得到;私有集;}公共字符串名称{得到;私有集;}publicstaticstringOSName{get;放;}privateDeviceInfo(){Id=GetId();可变设备Information=newEasClientDeviceInformation();Model=deviceInformation.SystemProductName;制造商=deviceInformation.SystemManufacturer;Name=deviceInformation.FriendlyName;OSName=deviceInformation.OperatingSystem;}privatestaticstringGetId(){if(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification")){vartoken=HardwareIdentification.GetPackageSpecificToken(null);varhardwareId=token.Id;vardataReader=Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);byte[]bytes=newbyte[hardwareId.Length];dataReader.ReadBytes(字节);返回BitConverter.ToString(bytes).Replace("-","");}thrownewException("NOAPIFORDEVICEIDPRESENT!");}}}看起vardeviceInformation=newEasClientDeviceInformation();字符串ID=deviceInformation.Id.ToString();正在做的魔术,引用EasClientDeviceInformation它提供了一个独特的IdId属性使用从MachineID、用户SID和程序包系列名称的SHA256哈希的前16个字节截断的GUID表示DeviceId,其中MachineID使用本地用户组的SID。但它只适用于Windows应用商店应用程序......所以必须有另一种解决方案。Windows1609更新(“周年更新”)请参阅此问答以获得获取ID的更好方法。旧操作系统版本的遗留信息您将需要添加对桌面和/或移动SDK的引用以针对硬件令牌进行构建。在运行时,您应该在使用API之前使用ApiInformation类型查询API是否存在(其他设备系列如Xbox没有)。也就是说,很多时候人们要求的设备ID实际上并不是解决他们问题的最佳方法-您确定需要在其整个生命周期内识别物理设备,即使所有权发生变化也是如此?EasClientDeviceInformation在Windows10移动版上不起作用。每部手机的设备ID都相同(我们所有的win10m客户都使用相同的GUID注册)我们需要该ID才能将推送消息发送到正确的手机。以上就是C#学习教程:如何在Windows10Universal中获取设备的唯一标识符?分享的所有内容,如果对你有用,需要了解更多C#学习教程,希望大家多多关注——//你可以用这个//它在windows10上与我配合得很好//replacethewordbioswithanyhardwarenameyouwant//dataalsocanbefoundwithusingwindowsapplicationnamed(wbemtest)usingSystem.Management;publicstaticasyncTaskReturnHardWareID(){strings="";任务task=Task.Run(()=>{ManagementObjectSearcherbios=newManagementObjectSearcher("SELECT*FROMWin32_BIOS");ManagementObjectCollectionbios_Collection=bios.Get();foreach(ManagementObjectobjinbios_Collection){s=obj["SerialNumber"].ToString();break;//break只是为了获取第一个找到的对象数据而已}});任务.WaitAll(任务);返回awaitTask.FromResult(s);}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
