解鎖AD上鎖定的帳戶時遇到一些問題。使用Systems.directoryservices.AccountManagement在c中解鎖活動目錄帳戶#
我會保持它很簡單。我假設該帳戶目前處於鎖定狀態。
UserPrincipal oUserPrincipal = ADMethods.GetUser("test.user");
oUserPrincipal.UnlockAccount();
oUserPrincipal.Save();`
oUserPrincipal使用上的TEST AD雖然PrincipalContext
現在,一個管理員帳戶返回..
oUserPrincipal.UnlockAccount();正在生成異常
System.UnauthorizedAccessException的
當檢查「測試AD服務器」上的日誌,它返回一個失敗的談判,指出「test.user」被鎖定。由於我使用管理員帳戶返回用戶主體,爲什麼unlockAccount方法會產生錯誤?
希望你的幫助。
例外情況如下。
System.UnauthorizedAccessException: Access is denied.
at System.DirectoryServices.Interop.UnsafeNativeMetho ds.IAds.SetInfo()
at System.DirectoryServices.DirectoryEntry.CommitChan ges()
at System.DirectoryServices.AccountManagement.SDSUtil s.WriteAttribute(String dePath, String attribute, Int32 value, NetCred credentials, AuthenticationTypes authTypes)
at System.DirectoryServices.AccountManagement.ADStore Ctx.WriteAttribute(Principal p, String attribute, Int32 value)
at System.DirectoryServices.AccountManagement.ADStore Ctx.UnlockAccount(AuthenticablePrincipal p)
at System.DirectoryServices.AccountManagement.Account Info.UnlockAccount()
at ADMethodsAccountManagement.UnlockUserAccount(Strin g sUserName) in C:\Users\christian.debono\documents\visual studio 2010\Projects\UnlockApp\UnlockApp\ADMethodsAccount Management.cs:line 182
at UnlockApp.Form1.UnlockButton_Click(Object sender, EventArgs e) in C:\Users\christian.debono\documents\visual studio 2010\Projects\UnlockApp\UnlockApp\Form1.cs:line 30
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
這:「訪問被拒絕」,似乎不言自明。 – 2010-11-10 08:49:23
是的,但我使用管理員權限運行可執行文件,並且我使用的服務帳戶是服務器和AD上的管理員。我可以使用該帳戶手動登錄服務器並執行更改,但不通過此代碼。 任何想法,爲什麼這是拋出一個Access拒絕異常? – christiandbn 2010-11-12 10:42:13