简体   繁体   English

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

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

Good morning, Using C# we are trying to create a new windows 8 / 8.1 user on windows store application. 早上好,我们正在尝试使用C#在Windows Store应用程序上创建一个新的Windows 8 / 8.1用户。 But the code using below is not working, because the namespace "System.DirectoryServices.AccountManagement" is not available. 但是下面使用的代码不起作用,因为名称空间“ 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;
        }
    }
}

We don´t know how to find the way to create a windows user (With or without password it doesnt matter) because all the namespaces necessaries for that are not available on Windows Store Application project. 我们不知道如何找到创建Windows用户的方法(使用或不使用密码都没有关系),因为Windows Store Application项目上没有所有必需的名称空间。

If we try to import some dll the error is: 如果我们尝试导入一些dll,则错误为:

"A reference to "[Dll path]" could not be added. The project targets '.Net Core' while the file targets '.NetFramework'. This is no a supported sceneraio" “无法添加对“ [Dll路径]”的引用。该项目的目标是“ .Net Core”,而文件的目标是“ .NetFramework”。这不是受支持的场景”

Is there any possible solution? 有没有可能的解决方案?

This is not possible, and shouldn't be. 这是不可能的,也不应该。 Windows Store apps don't have the rights to create users because it would be a huge huge security risk! Windows应用商店应用无权创建用户,因为这将带来巨大的巨大安全风险! Why are you even trying to do this? 您为什么还要尝试这样做?

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

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