guaikahenguai Posted May 12, 2023 Share Posted May 12, 2023 I want to modify the user account "User Cannot Change Password" option by remotely connecting to the Active Directory (using the same way as RSAT). Current situation: I run the following script on the local computer to connect to the Active Directory and modify the "User Cannot Change Password" option of the specified user account, the setting does not take effect. expandcollapse popup#NoTrayIcon ;~ #RequireAdmin #include <AD.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _AD_ErrorNotify(1) Global $AD_user = "gg.com\ADadmin" ;ADadmin member of Domain Admins Global $AD_pswd = "Abcd.123654" Global $AD_domain = "gg.com" Global $nMsg, $sUser, $sUser1, $sUser2 _AD_Open($AD_user,$AD_pswd,"",$AD_domain) If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) Global $iReply = MsgBox(308, "Enables/Disable change password", "This script Enables/Disable the specified user to change their password." & @CRLF & @CRLF & _ "Are you sure you want to change the Active Directory?") If $iReply <> 6 Then Exit #region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Active Directory Functions - Example 1", 714, 124) GUICtrlCreateLabel("User to change (FQDN or sAMAccountName):", 8, 10, 231, 17) Global $IUser = GUICtrlCreateInput("", 241, 10, 459, 21) Global $BDisable = GUICtrlCreateButton( "Disable", 8, 72, 121, 33) Global $BEnable = GUICtrlCreateButton( "Enable", 260, 72, 121, 33) Global $BCancel = GUICtrlCreateButton("Cancel", 628, 72, 73, 33, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON)) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $BCancel Exit Case $BDisable $sUser1 = GUICtrlRead($IUser) _DisablePasswordChange($sUser1) ExitLoop Case $BEnable $sUser2 = GUICtrlRead($IUser) _EnablePasswordChange($sUser2) ExitLoop EndSwitch WEnd Func _DisablePasswordChange($sUser) Local $iValue1 = _AD_DisablePasswordChange($sUser) ConsoleWrite("Result: " & $iValue1 & ", error: " & @error & ", extended: " & @extended) If $iValue1 = 1 Then MsgBox(64, "Disable Password Change", "User '" & $sUser & "' successfully changed") ElseIf @error = 1 Then MsgBox(64, "Disable Password Change", "User '" & $sUser & "' does not exist") Else MsgBox(64, "Disable Password Change", "Return code '" & @error & "' from Active Directory") EndIf EndFunc Func _EnablePasswordChange($sUser) Local $iValue2 = _AD_EnablePasswordChange($sUser) ConsoleWrite("Result: " & $iValue2 & ", error: " & @error & ", extended: " & @extended) If $iValue2 = 1 Then MsgBox(64, "Enable Password Change", "User '" & $sUser & "' successfully changed") ElseIf @error = 1 Then MsgBox(64, "Enable Password Change", "User '" & $sUser & "' does not exist") Else MsgBox(64, "Enable Password Change", "Return code '" & @error & "' from Active Directory") EndIf EndFunc _AD_Close() I get the _AD_ErrorNotify(1) error message: COM Error Encountered in _AD_DisablePasswordChange.au3 AD UDF version = 1.6.1 @AutoItVersion = 3.3.15.4 @AutoItX64 = 1 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_10Scriptline = 1322NumberHex = 0x80020009 Number = -2147352567 WinDescription = Exception occurred. Description = Source = HelpFile = HelpContext = 0 LastDllError = 0 The script can modify the user's "User Cannot Change Password" option and take effect when running in Active Directory. I've been working on this for a few days and can't figure it out. Does anyone have the same problem and I need help.😭 thanks in advance! 20Ice18 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now