简体   繁体   中英

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. But the code using below is not working, because the namespace "System.DirectoryServices.AccountManagement" is not available.

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.

If we try to import some dll the error is:

"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"

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! Why are you even trying to do this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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