0

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?

1 Answers1

2

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?

roryok
  • 9,325
  • 17
  • 71
  • 138
  • Correct. AccountManagement is a "full trust" API which isn't available to Store apps. There are a number of APIs like this which are meant for the OS itself, inbox (privileged) apps like the Store/PC Settings, and desktop apps. – Kraig Brockschmidt - MSFT Dec 04 '14 at 19:40