本文介绍了在本地计算机中创建用户收到错误,如在C#中拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试从sharepoint在本地计算机上创建用户。在创建用户时,我收到错误,如访问被拒绝。我使用下面的代码在本地机器上创建用户。 // 创建新用户 PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Machine ); UserPrincipal oUserPrincipal = new UserPrincipal(oPrincipalContext, YourUserName, Password.123, true / * 是否启用* / ); oUserPrincipal.UserPrincipalName = YourUserName; // oUserPrincipal.GivenName =Given Name; // oUserPrincipal.Surname =Surname; oUserPrincipal.Save(); 请告诉我如何诊断这个问题解决方案 如果您在提升的权限下运行应用程序,则只能执行此类操作。对于Windows 7或更高版本,仅在管理帐户下执行此操作是不够的;您还需要以管理员身份运行。方法如下: http://www.sevenforums.com/tutorials/ 11841-run-administrator.html [ ^ ]。 -SA I am trying to create user in local machine from sharepoint. while creating user I am getting error like Access is denied. I am using below code for creating users in local machine. //Create New UserPrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Machine); UserPrincipal oUserPrincipal = new UserPrincipal(oPrincipalContext, "YourUserName", "Password.123", true /*Enabled or not*/); oUserPrincipal.UserPrincipalName = "YourUserName"; //oUserPrincipal.GivenName = "Given Name"; //oUserPrincipal.Surname = "Surname"; oUserPrincipal.Save();Please tell me how to diagnose this problem 解决方案 You can only do such thing if you run your application under elevated privileges. Doing it just under the administrative account is not enough for Windows 7 or later; you also need to "Run as Administrator". Here is how:http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].—SA 这篇关于在本地计算机中创建用户收到错误,如在C#中拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 05:23