1

我正在使用Windows 10计算机和Visual Studio 2015来运行具有Windows运行时组件和通用Windows应用程序(UWA)的项目。 UWA引用了Windows运行时组件,它执行获取登录用户的UserIdentity(Window NT ID,即“DomainName/UserName”)的任务。创建UWA测试项目以调试运行时组件。如果我们在运行时组件中获得UserIdentity,那么我们可以使用组件引用来访问我们的Windows10 cordova项目以获取JavaScript中的UserIdentity。
在这里,我们正面临的问题,没有任何代码工作获取登录用户的域名/用户名。我们已经从Windows升级验证码8.1至10戴这个代码与Windows 8.1中伟大的工作,但在Windows 10有问题,下面是我们使用得到的UserIdentity代码:通用Windows应用程序运行时组件在Windows 10上使用Visual Studio 2015时不导致UserIdentity

public sealed class getNTID 
{ 
    public static IAsyncOperation<string> DownloadAsStringsAsync() 
    { 

     return Task.Run<string>(async() => 
     { 

      IReadOnlyList<User> users = await User.FindAllAsync(); 

      var current = users.Where(p => p.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated && 
            p.Type == UserType.LocalUser).FirstOrDefault(); 


      var data = await current.GetPropertyAsync(KnownUserProperties.AccountName); 

      return data.ToString(); 

     }).AsAsyncOperation(); 
    } 
} 

我们越来越空字符串在数据变量末尾。如果有人分享他们的经验,或者他们遇到了这样的问题,那就太好了。

回答

0

User class是Windows 10的新增功能,与您在Windows 8.1中使用的UserInformation不同。访问用户的个人信息是您必须申请的权限,因此在商店应用程序的Package.appxmanifest中,您需要启用Capabilities选项卡中的用户帐户信息功能。

当您拨打GetPropertyAsync时,您的用户将从系统获得如下权限提示,接受该提示即可获得该权限。更多关于性能的细节请参考this documententer image description here

对于GetPropertyAsync方法,如果属性丢失或不可用,则返回空字符串。所以,如果你已经完成,但你仍然得到空值,也许该属性是失踪或不可用。

这是我通过运行代码获取当前用户DomainName的结果(我也把代码放在了windows运行时组件中)。

enter image description here

更多细节请参考official sample

相关问题