Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
I sent an email to you Shawn with the script and some additional info. The code should work in any environment without changes. It could probably use a little cleanup as I haven't gone over it cosmetically at this point. But anyway, here it is...
*UPDATE* I just added functionality so that the script gets the Minimum Password Value from the Domain and uses that to check against the length of the new password set instead of just using the number 6. Hopefully the new code copies OK . code:
BREAK ON
; REQUIRES: ; ; KIXTART 4.02 ; KIXFORMS BUILD 27 ; WINDOWS 2K/XP ; ; WRITTEN BY SHAWN TASSIE ; MODIFIED BY BEN DULANEY ; Find out if User is an Administrator, if so enable all features $ADMINUSER=0 $ADSUSER1=GETOBJECT("WinNT://@LDOMAIN/@USERID,User") FOR EACH $ELEMENT IN $ADSUSER1.GROUPS IF $ELEMENT.NAME="DOMAIN ADMINS" $ADMINUSER=1 ENDIF NEXT
$FORM = CREATEOBJECT("Kixtart.FORM")
$FORM.CAPTION = "User Manager" $FORM.SCALEHEIGHT = 402 $FORM.SCALEWIDTH = 600 $FORM.FONTNAME = "Arial" $FORM.FONTSIZE = 9 $FORM.CENTER
$fraBanner = $FORM.PictureBox $fraBanner.BACKCOLOR = $FORM.RGB(255,255,255) $fraBanner.HEIGHT = 70 $fraBanner.LEFT = 10 $fraBanner.TOP = 10 $fraBanner.WIDTH = 585
$fraDetails = $FORM.Frame("Details") $fraDetails.HEIGHT = 300 $fraDetails.LEFT = 8 $fraDetails.TOP = 95 $fraDetails.WIDTH = 585 $txtUsername = $fraDetails.TextBox $txtUsername.HEIGHT = 19 $txtUsername.LEFT = 104 $txtUsername.TOP = 24 $txtUsername.Text = "" $txtUsername.WIDTH = 161 $cmdFindUser = $fraDetails.CommandButton("Find User") $cmdFindUser.DEFAULT = 1 ; True $cmdFindUser.FONTNAME = "Arial" $cmdFindUser.FONTSIZE = 10 $cmdFindUser.FONTBOLD = 1 $cmdFindUser.LEFT = 272 $cmdFindUser.TOP = 24 $cmdFindUser.WIDTH = 129 $cmdFindUser.HEIGHT = 19 $cmdFindUser.OnClick = "cmdFindUser_Click()" $txtDisplayName = $fraDetails.TextBox $txtDisplayName.HEIGHT = 19 $txtDisplayName.LEFT = 104 $txtDisplayName.TabStop = 0 ; False $txtDisplayName.TOP = 56 $txtDisplayName.WIDTH = 297 $txtDisplayName.Enabled = 1 $txtDisplayName.BACKCOLOR = $FORM.BACKCOLOR $lblDisplayName = $fraDetails.Label("Full Name:") $lblDisplayName.WIDTH = 75 $lblDisplayName.LEFT = $txtDisplayName.LEFT - $lblDisplayName.WIDTH $lblDisplayName.TOP = $txtDisplayName.TOP $txtPassword = $fraDetails.TextBox $txtPassword.HEIGHT = 19 $txtPassword.LEFT = 104 $txtPassword.PasswordChar = "" $txtPassword.TOP = 88 $txtPassword.WIDTH = 161 $txtPassword.Enabled = 0 $cmdSetPassword = $fraDetails.CommandButton("Set Password") $cmdSetPassword.FONTNAME = "Arial" $cmdSetPassword.FONTSIZE = 10 $cmdSetPassword.FONTBOLD = 1 $cmdSetPassword.LEFT = 272 $cmdSetPassword.TOP = 88 $cmdSetPassword.WIDTH = 129 $cmdSetPassword.HEIGHT = 19 $cmdSetPassword.Enabled = 0 $cmdSetPassword.OnClick = "cmdSetPassword_Click()" $txtExpiryDate = $fraDetails.TextBox $txtExpiryDate.HEIGHT = 19 $txtExpiryDate.LEFT = 104 $txtExpiryDate.TOP = 120 $txtExpiryDate.WIDTH = 161 $txtExpiryDate.Enabled = 0 $lblPassword = $fraDetails.Label("Password:") $lblPassword.WIDTH = 75 $lblPassword.LEFT = $txtPassword.LEFT - $lblPassword.WIDTH $lblPassword.TOP = $txtPassword.TOP $lblExpiryDate = $fraDetails.Label("Expire Date:") $lblExpiryDate.WIDTH = 75 $lblExpiryDate.LEFT = $txtExpiryDate.LEFT - $lblExpiryDate.WIDTH $lblExpiryDate.TOP = $txtExpiryDate.TOP $cmdChangeExpiryDate = $fraDetails.CommandButton("Change Date") $cmdChangeExpiryDate.FONTNAME = "Arial" $cmdChangeExpiryDate.FONTSIZE = 10 $cmdChangeExpiryDate.FONTBOLD = 1 $cmdChangeExpiryDate.LEFT = 272 $cmdChangeExpiryDate.TOP = 120 $cmdChangeExpiryDate.WIDTH = 129 $cmdChangeExpiryDate.HEIGHT = 19 $cmdChangeExpiryDate.OnClick = "cmdChangeExpiryDate_Click()" $cmdChangeExpiryDate.Enabled = 0 $lstGroups = $fraDetails.ListBox $lstGroups.HEIGHT = 134 $lstGroups.LEFT = 104 $lstGroups.TOP = 152 $lstGroups.WIDTH = 297 $lstGroups.Enabled = 0 $lblGroups = $fraDetails.Label("Groups:") $lblGroups.WIDTH = 75 $lblGroups.LEFT = $lstGroups.LEFT - $lblGroups.WIDTH $lblGroups.TOP = $lstGroups.TOP $txtBadLoginCount = $fraDetails.TextBox $txtBadLoginCount.HEIGHT = 19 $txtBadLoginCount.LEFT = 9 + 420 + 75 $txtBadLoginCount.TabStop = 0 ; False $txtBadLoginCount.TOP = 26 + 20 + 105 $txtBadLoginCount.WIDTH = 20 $txtBadLoginCount.BACKCOLOR = $FORM.BACKCOLOR $lblBadLoginCount = $fraDetails.Label("Bad Logins:") $lblBadLoginCount.WIDTH = 75 $lblBadLoginCount.LEFT = 9 + 420 ; X + Y (Y = $fraStatus.LEFT) $lblBadLoginCount.TOP = 26 + 20 + 105 ; X + Y + Z CHOPPED (Y = $fraStatus.TOP & Z = $fraStatus.HEIGHT) $cmdExit = $fraDetails.CommandButton("Exit") $cmdExit.FONTNAME = "Arial" $cmdExit.FONTSIZE = 10 $cmdExit.FONTBOLD = 1 $cmdExit.TOP = 267 $cmdExit.WIDTH = 129 $cmdExit.HEIGHT = 19 $cmdExit.LEFT = 445 $cmdExit.OnClick = "quit()" $fraStatus = $fraDetails.Frame $fraStatus.BACKCOLOR = $FORM.BACKCOLOR $fraStatus.CAPTION = "Account Status" $fraStatus.HEIGHT = 105 $fraStatus.LEFT = 420 ; 416 $fraStatus.TOP = 20 ; 224 $fraStatus.WIDTH = 155 $chkAccountDisabled = $fraStatus.CheckBox("Account Disabled") $chkAccountDisabled.LEFT = 10 $chkAccountDisabled.TabStop = 0 ; False $chkAccountDisabled.TOP = 24 $chkAccountDisabled.OnClick = "chkAccountDisabled_Click()" $chkAccountDisabled.Enabled = 0 $chkAccountLocked = $fraStatus.CheckBox("Account Locked") $chkAccountLocked.CAPTION = "Account Locked" $chkAccountLocked.LEFT = 10 $chkAccountLocked.TabStop = 0 ; False $chkAccountLocked.TOP = 56 $chkAccountLocked.OnClick = "chkAccountLocked_Click()" $chkAccountLocked.Enabled = 0 $lblUsername = $fraDetails.Label $lblUsername.CAPTION = "Username:" $lblUsername.HEIGHT = $txtUsername.HEIGHT $lblUsername.WIDTH = 75 $lblUsername.LEFT = $txtUsername.LEFT - $lblUsername.WIDTH $lblUsername.TOP = $txtUsername.TOP ; Draw on the banner $fraBanner.FONTSIZE = 20 $fraBanner.FONTNAME = "verdana" $fraBanner.ForeColor = 0 $fraBanner.PrintXY(20,0,"User Manager") $fraBanner.FONTSIZE = 8 $fraBanner.ForeColor = $FORM.RGB(0,100,100) $fraBanner.PrintXY(23,32,"Powered by KiX v@KIX and Kixforms Build 27") $fraBanner.FONTBOLD = 1 $fraBanner.FONTSIZE = 11 $fraBanner.PrintXY(23,46,"Welcome @FULLNAME") $fraBanner.FONTBOLD = 0 $fraBanner.FONTSIZE = 10
Dim $strUserName Dim $strUserPath Dim $strDomainPath $txtUsername.SelLength = Len($txtUsername.Text) $FORM.Show $txtUsername.SetFocus
While $FORM.Visible $=Execute($FORM.DoEvents) Loop Exit 1 Function cmdFindUser_Click() Dim $Wait $Wait = CREATEOBJECT("Kixtart.FORM") $Wait.CAPTION = "One moment please..." $Wait.SCALEWIDTH = 500 $Wait.SCALEHEIGHT = 100 $Wait.FONTSIZE = 14 $Wait.FONTNAME = "Arial" $Wait.PrintXY(30,30,"Searching Active Directory, one moment please...") $Wait.CENTER Dim $adsUser,$adsGroup
If $txtUsername.Text = "" $= $FORM.MsgBox("You must specify a username before CHOPPED clicking Find.", "Username invalid") $txtUsername.Text = $strUserName Exit Sub Else $strUserName = $txtUsername.Text Endif
$Wait.Show $strUserPath = "WinNT://@LDOMAIN/$strUserName,User" $adsUser = GetObject($strUserPath) If Not $adsUser ; User does not exist $= $FORM.MsgBox("A user called (" + $txtUsername.Text + ") CHOPPED does not exist.", "Username invalid") ; Disable the controls $chkAccountDisabled.Enabled = 0 $cmdSetPassword.Enabled = 0 $cmdChangeExpiryDate.Enabled = 0 $txtPassword.Enabled = 0 $cmdChangeExpiryDate.Enabled = 0 $txtPassword.Text = "" $txtDisplayName.Text = "" $txtExpiryDate.Text = "" $txtBadLoginCount.Text = "" $lstGroups.Clear Else $txtPassword.Text = "" $txtDisplayName.Text = "" $txtExpiryDate.Text = "" $txtBadLoginCount.Text = "" $lstGroups.Clear $lstGroups.
; User exists so bind to it $adsUser.GetInfo $txtDisplayName.Text = $adsUser.FullName $txtExpiryDate.Text = $adsUser.AccountExpirationDate
If $adsUser.AccountDisabled ; Check the disabled box $chkAccountDisabled.Value = 1 Else
; Uncheck the disabled box $chkAccountDisabled.Value = 0 EndIf
If $adsUser.IsAccountLocked ; Check the locked box $chkAccountLocked.Value = 1 ; Enable the checkbox so that the account can be unlocked $chkAccountLocked.Enabled = 1 Else ; Uncheck the locked box $chkAccountLocked.Value = 0 EndIf
For Each $adsGroup In $adsUser.Groups $lstGroups.AddItem ($adsGroup.Name) Next
$strBLC = $adsUser.BadLoginCount If @ERROR $txtBadLoginCount.Text = 0 Else $txtBadLoginCount.Text = $strBLC EndIf ;Enable the controls $chkAccountDisabled.Enabled = $ADMINUSER $cmdSetPassword.Enabled = 1 $cmdChangeExpiryDate.Enabled = $ADMINUSER $txtPassword.Enabled = 1 $txtExpiryDate.Enabled = $ADMINUSER $lstGroups.Enabled = 1 $adsUser = 0 $adsGroup = 0 $txtUsername.SetFocus Endif $FORM.Refresh $txtUsername.SetFocus EndFunction Function chkAccountDisabled_Click() Dim $adsUser $adsUser = GetObject($strUserPath) If $chkAccountDisabled.Value = 0 ; Enable account $adsUser.AccountDisabled = 0 $adsUser.SetInfo IF @ERROR=0 $=$FORM.MsgBox("The user (" + $strUserName + ") has CHOPPED been enabled.", "User enabled") ELSE $=$FORM.MsgBox("The user (" + $strUserName + ") could CHOPPED not be enabled.","Not Authorized") ENDIF Else ; Disable Account $adsUser.AccountDisabled = 1 $adsUser.SetInfo IF @ERROR=0 $= $FORM.MsgBox("The user (" + $strUserName + ") has CHOPPED been disabled.", "User disabled") ELSE $=$FORM.MsgBox("The user (" + $strUserName + ") could CHOPPED not be disabled.","Not Authorized") ENDIF EndIf $adsUser = 0 EndFunction Function chkAccountLocked_Click() Dim $adsUser If $chkAccountLocked.Value = 0 ; Unlock the account $adsUser = GetObject($strUserPath) $adsUser.IsAccountLocked = 0 $adsUser.SetInfo IF @ERROR=0 $=$FORM.MsgBox("The user (" + $strUserName + ") has CHOPPED been unlocked.", "User enabled") ELSE $=$FORM.MsgBox("The user (" + $strUserName + ") could CHOPPED not be unlocked.","Not Authorized") $chkAccountLocked.Value = 1 ENDIF EndIf ; Disable the checkbox $chkAccountLocked.Enabled = 0 $adsUser = Nothing EndFunction Function cmdSetPassword_Click() ; Get Minimum Password Length Allowed from Domain Policy $strDomainPath="WinNT://@LDOMAIN,Domain" $adsDomain = GetObject($strDomainPath) $intMinPasswordLength=$adsDomain.MinPasswordLength $adsDomain = Nothing
$adsUser = GetObject($strUserPath) If $txtPassword.Text = "" $= $FORM.MsgBox("The password cannot be empty.", "User CHOPPED password change") Else If Len($txtPassword.Text) < $intMinPasswordLength $= $FORM.MsgBox("The password cannot be less than " + CHOPPED $intMinPasswordLength + " characters long.", CHOPPED "User password change") Else $adsUser.SetPassword($txtPassword.Text) IF @ERROR=0 $=$FORM.MsgBox("The password has been changed CHOPPED to (" + $txtPassword.Text + ").", "User Password Change") ELSE $=$FORM.MsgBox("The password could not be CHOPPED changed.","Not Authorized") ENDIF EndIf EndIf $txtPassword.Text = "" $adsUser = Nothing EndFunction Function cmdChangeExpiryDate_Click() Dim $adsUser $adsUser = GetObject($strUserPath) If $txtExpiryDate.Text = "" $= $FORM.MsgBox("The expiration date cannot be empty.", CHOPPED "User expire date change") $txtExpiryDate.Text = $adsUser.AccountExpirationDate Else $adsUser.AccountExpirationDate = $txtExpiryDate.Text $adsUser.SetInfo If @ERROR $= $FORM.MsgBox("Expiration date has not been changed CHOPPED due to an error.", "User expire date change") Else $= $FORM.MsgBox("Expiration date is changed to (" + CHOPPED $txtExpiryDate.Text + ").", "User expire date change") EndIf EndIf $adsUser = Nothing EndFunction
BTW, I compacted a few lines so the post wouldn't be so wide. I added the word 'CHOPPED' in front of those lines to make it easy to fix. If someone can tell me how to do that without breaking the code I'll go back and fix it. If it's cut and pasted, it will not work without those lines being fixed.
Thanks, Ben [ 16. August 2002, 21:51: Message edited by: Ben Dulaney ]
|