繁体   English   中英

使用Windows Store App创建新的Windows 8 / 8.1用户

[英]Create New Windows 8 / 8.1 User with Windows Store App

早上好,我们正在尝试使用C#在Windows Store应用程序上创建一个新的Windows 8 / 8.1用户。 但是下面使用的代码不起作用,因为名称空间“ System.DirectoryServices.AccountManagement”不可用。

public UserPrincipal CreateNewUser(string a_userName, string sPassword)
{
    if (!UserExists(a_userName))
    {
        PrincipalContext oPrincipalContext = GetPrincipalContext();

        UserPrincipal oUserPrincipal = new UserPrincipal(oPrincipalContext);
        oUserPrincipal.Name = a_userName;
        oUserPrincipal.SetPassword(sPassword);
        //User Log on Name
        oUserPrincipal.UserPrincipalName = a_userName;
        oUserPrincipal.Save();

        return oUserPrincipal;
    }

    // if it already exists, return null        
    return null;
}

private PrincipalContext GetPrincipalContext()
{
    PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Machine);
    return oPrincipalContext;
}

private bool UserExists(string a_userName)
{
    using (var pc = new PrincipalContext(ContextType.Machine))
    {
        using (var p = Principal.FindByIdentity(pc, IdentityType.SamAccountName, a_userName))
        {
            return p != null;
        }
    }
}

我们不知道如何找到创建Windows用户的方法(使用或不使用密码都没有关系),因为Windows Store Application项目上没有所有必需的名称空间。

如果我们尝试导入一些dll,则错误为:

“无法添加对“ [Dll路径]”的引用。该项目的目标是“ .Net Core”,而文件的目标是“ .NetFramework”。这不是受支持的场景”

有没有可能的解决方案?

这是不可能的,也不应该。 Windows应用商店应用无权创建用户,因为这将带来巨大的巨大安全风险! 您为什么还要尝试这样做?

暂无
暂无

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

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