簡體   English   中英

如何設置“用戶無法更改密碼” AD屬性

[英]How to set “user cannot change password” AD attribute

我試圖弄清楚如何使用VB.NET設置AD的“用戶無法更改密碼”屬性。

我最初希望使用在http://support.microsoft.com/kb/305144上找到的UserAccountControl標志,但是我意識到您無法像預期的那樣設置PASSWD_CANT_CHANGE標志。 這使我想到了此帖子, 阻止Active Directory用戶使用DirectoryServices更改其密碼,但是我無法進行保存。

這是我現在擁有的代碼。

        Dim domainContext As PrincipalContext = New PrincipalContext(ContextType.Domain)
        Dim user As UserPrincipal = UserPrincipal.FindByIdentity(domainContext, "user5")
        user.UserCannotChangePassword = True
        user.Save(domainContext)

每次嘗試對此進行保存時,都會收到InvalidOperationException。 此文檔也不太有用: http : //msdn.microsoft.com/en-us/library/bb335863.aspx

對我來說奇怪的是,如果我為該UserPrincipal對象設置了一個不同的屬性(如SamAccountName),則保存效果很好,但是一旦引入了UserCannotChangePassword屬性,保存就會失敗。

我已驗證我用來執行此操作的用戶具有適當的特權,但是我不確定從這里去哪里...有什么想法嗎?

找到了一種古老的方法來完成此任務,感謝您為我指明了正確的方向@juergen d。 猜猜我必須解決。

        Dim objThisUser As IADs
        Dim intUserFlags As Integer

        ' Bind to the user object with the current credentials.
        objThisUser = GetObject("WinNT://" + gstrDomain + "/" + "user5")

        intUserFlags = objThisUser.Get("userFlags")

        'can't change
        intUserFlags = intUserFlags Or ADS_UF_PASSWD_CANT_CHANGE

        ' Modify the userFlags property.
        objThisUser.Put("userFlags", intUserFlags)

        ' Commit the changes
        objThisUser.SetInfo()

我一直都在尋求一個完美的解決方案,但是卻無法節省下來的錢。 我猜這很好。 使用此功能僅意味着多幾行代碼,並且適應性差一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM