簡體   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