Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Gang,
Well, since nobody thought KiXlander was neat here`s a prototype of a new script that allows one to "quicky" Manage User Details (MUD) using Active Directory. Instead of using USRMGR for domains, and having to enumerate all those users and groups into a listbox, this script allows one to perform a single user query, then (in this release) set the password and enable/disable the account.
The reason its a prototype is that it will be using some of the new features of the next release, like setting the PasswordChar on a textbox, etc.
To run this script, you will need a Windows 2K/XP machine, KiXtart 4.0 and the Kixforms Library Build 8, and you can get that from here:
The Kixforms Library
Heres a screenshot:
And heres the script:
code:
Break On
; REQUIRES: ; ; KIXTART 4.02 ; KIXFORMS BUILD 8 ; WINDOWS 2K/XP ; $Form = CreateObject("Kixtart.Form") $Form.Caption = "Modify User Details - KiXtart" $Form.ScaleHeight = 506 $Form.ScaleWidth = 600 $Form.FontName = "Arial" $Form.FontSize = 9 $Form.Center $fraBanner = $Form.PictureBox $fraBanner.BackColor = $Form.RGB(255,255,255) $fraBanner.Height = 137 $fraBanner.Left = 10 $fraBanner.Top = 10 $fraBanner.Width = 585 $fraDetails = $Form.Frame("Details") $fraDetails.Height = 345 $fraDetails.Left = 8 $fraDetails.Top = 152 $fraDetails.Width = 585 $txtUsername = $fraDetails.TextBox $txtUsername.Height = 25 $txtUsername.Left = 104 $txtUsername.Top = 24 $txtUsername.Text = "" $txtUsername.Width = 161 $cmdFindUser = $fraDetails.CommandButton("Find User!") $cmdFindUser.Default = 1 ; True $cmdFindUser.FontName = "Comic Sans MS" $cmdFindUser.FontSize = 12 $cmdFindUser.FontBold = 1 $cmdFindUser.Left = 272 $cmdFindUser.Top = 24 $cmdFindUser.Width = 129 $cmdFindUser.OnClick = "cmdFindUser_Click()" $txtDisplayName = $fraDetails.TextBox $txtDisplayName.Height = 25 $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 = 25 $txtPassword.Left = 104 $txtPassword.PasswordChar = "" $txtPassword.Top = 88 $txtPassword.Width = 161 $txtPassword.Enabled = 0 $cmdSetPassword = $fraDetails.CommandButton("Set Password!") $cmdSetPassword.FontName = "Comic Sans MS" $cmdSetPassword.FontSize = 12 $cmdSetPassword.FontBold = 1 $cmdSetPassword.Left = 272 $cmdSetPassword.Top = 88 $cmdSetPassword.Width = 129 $cmdSetPassword.Enabled = 0 $cmdSetPassword.OnClick = "cmdSetPassword_Click()" $txtExpiryDate = $fraDetails.TextBox $txtExpiryDate.Height = 25 $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("Expiry Date:") $lblExpiryDate.Width = 75 $lblExpiryDate.Left = $txtExpiryDate.Left - $lblExpiryDate.Width $lblExpiryDate.Top = $txtExpiryDate.Top $cmdChangeExpiryDate = $fraDetails.CommandButton("Change Date!") $cmdChangeExpiryDate.FontName = "Comic Sans MS" $cmdChangeExpiryDate.FontSize = 12 $cmdChangeExpiryDate.FontBold = 1 $cmdChangeExpiryDate.Left = 272 $cmdChangeExpiryDate.Top = 120 $cmdChangeExpiryDate.Width = 129 $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 = 25 $txtBadLoginCount.Left = 104 $txtBadLoginCount.TabStop = 0 ; False $txtBadLoginCount.Top = 296 $txtBadLoginCount.Width = 161 $txtBadLoginCount.BackColor = $Form.BackColor $lblBadLoginCount = $fraDetails.Label("Bad Logins:") $lblBadLoginCount.Width = 75 $lblBadLoginCount.Left = $txtBadLoginCount.Left - $lblBadLoginCount.Width $lblBadLoginCount.Top = $txtBadLoginCount.Top $cmdExit = $fraDetails.CommandButton("Exit!") $cmdExit.FontName = "Comic Sans MS" $cmdExit.FontSize = 12 $cmdExit.FontBold = 1 $cmdExit.Top = 296 $cmdExit.Width = 129 $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 = 16 $fraBanner.FontName = "verdana" $fraBanner.FontSize = 28 $fraBanner.ForeColor = $Form.RGB(100,200,200) $fraBanner.PrintXY(23,10,"Modify User Details") $fraBanner.ForeColor = 0 $fraBanner.PrintXY(20,7,"Modify User Details") $fraBanner.FontSize = 12 $fraBanner.ForeColor = $Form.RGB(0,100,100) $fraBanner.PrintXY(23,58,"Powered by KiXtart v@KIX and Kixforms Build 8") $fraBanner.FontBold = 1 $fraBanner.PrintXY(23,80,"Welcome @USERID") $fraBanner.FontBold = 0 $fraBanner.FontSize = 10 $fraBanner.ForeColor = $Form.RGB(0,100,100)
Dim $strUserName Dim $strUserPath $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 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 + ") 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 = True 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 = 1 $cmdSetPassword.Enabled = 1 $cmdChangeExpiryDate.Enabled = 1 $txtPassword.Enabled = 1 $txtExpiryDate.Enabled = 1 $lstGroups.Enabled = 1 $adsUser = 0 $adsGroup = 0 $txtUsername.SetFocus Endif $Form.Refresh $txtUsername.SetFocus EndFunction Function chkAccountDisabled_Click() Dim $adsUser $adsUser = GetObject($strUserPath) $adsUser.GetInfo If $chkAccountDisabled.Value = 0 ; Enable account $adsUser.AccountDisabled = 0 $adsUser.SetInfo $= $Form.MsgBox("The user (" + $strUserName + ") has been enabled.", "User enabled") Else ; Disable Account $adsUser.AccountDisabled = 1 $adsUser.SetInfo $= $Form.MsgBox("The user (" + $strUserName + ") has been disabled.", "User disabled") EndIf $adsUser = 0 EndFunction Function chkAccountLocked_Click() Dim $adsUser If $chkAccountLocked.Value = 0 ; Unlock the account $adsUser = GetObject($strUserPath) $adsUser.GetInfo $adsUser.IsAccountLocked = 0 $adsUser.SetInfo $= $Form.MsgBox("The user (" + $strUserName + ") has been unlocked.", "User enabled") EndIf ; Disable the checkbox $chkAccountLocked.Enabled = 0 $adsUser = Nothing EndFunction Function cmdSetPassword_Click() $adsUser = GetObject($strUserPath) $adsUser.GetInfo If $txtPassword.Text = "" $= $Form.MsgBox("The password cannot be empty.", "User password change", 1) Else If Len($txtPassword.Text) < 6 $= $Form.MsgBox("The password cannot be less than 6 characters long.", "User password change", 1) Else $adsUser.SetPassword($txtPassword.Text) $= $Form.MsgBox("The password has been changed to (" + $txtPassword.Text + ").", "User password change", 1) EndIf EndIf $txtPassword.Text = "" $adsUser = Nothing EndFunction Function cmdChangeExpiryDate_Click() Dim $adsUser $adsUser = GetObject($strUserPath) $adsUser.GetInfo If $txtExpiryDate.Text = "" $= $Form.MsgBox("The expiry date cannot be empty.", "User expiry date change", 1) $txtExpiryDate.Text = $adsUser.AccountExpirationDate Else $adsUser.AccountExpirationDate = $txtExpiryDate.Text $adsUser.SetInfo If @ERROR $= $Form.MsgBox("The expiry date has not been changed due to an error.", "User expiry date change") Else $= $Form.MsgBox("The expiry date been changed to (" + $txtExpiryDate.Text + ").", "User expiry date change") EndIf EndIf $adsUser = Nothing EndFunction
-Shawn [ 16 March 2002, 15:18: Message edited by: Shawn ]
|