Code:
Break On
$System = CreateObject("Kixtart.System")
;************* Form **************
$ADForm = $System.Form()
$ADForm.FormBorderStyle = 3
$ADForm.Height = 435
$ADForm.MaximizeBox = "False"
$ADForm.MinimizeBox = "False"
$ADForm.Text = ""
$ADForm.Width = 195
;**************************************
;************* TextBox1 **************
$ADTextBox1 = $ADForm.Controls.TextBox("", 5, 5, 175, 20)
$ADTextBox1.OnKeyDown = "FindUser()"
;**************************************
;************* ListBox1 **************
$ADListBox1 = $ADForm.Controls.ListBox("", 5, 35, 175, 330)
$ADlistBox1.Sorted = "True"
$ADlistBox1.OnClick = "ListBoxClicked"
$ADlistBox1.OnDoubleClick = "ListBoxdblClicked"
;**************************************
;************* TextBox2 **************
$ADTextBox2 = $ADForm.Controls.TextBox("", 5, 375, 175, 20)
$ADTextBox2.BackColor = 212,208,200
$ADTextBox2.BorderStyle = 0
$ADTextBox2.ReadOnly = "True"
$ADTextBox2.TabStop = "False"
;**************************************
;************* ProgForm **************
$ProgForm = $System.Form()
$ProgForm.FormBorderStyle = 0
$ProgForm.Height = 60
$ProgForm.StartPosition = 4
$ProgForm.Text = ""
$ProgForm.TopMost = "True"
$ProgForm.Width = 300
;**************************************
;************* PBar1 **************
$PBar1 = $ProgForm.Controls.ProgressBar("PBar1", 15, 30, 267, 11)
;**************************************
;************* Label1 **************
$pbLabel1 = $ProgForm.Controls.Label("Collecting Usernames", 60, 10, 170, 16)
GetUsers()
While $ADForm.Visible
$=Execute($ADForm.DoEvents())
Loop
Exit 1
Function GetUsers()
$target = $button
$ADForm.Show
if $adListBox1.ListCount <1
$ProgForm.Show
$oDomain = GetObject("WinNT://@LDomain")
$oDomain.filter = "User",""
For Each $oUser In $oDomain
if instr($oUser.FullName,',') or instr($oUser.FullName,'=') > 0
$adlistbox1.additem($oUser.FullName)
$adTextBox2.text = '' + $adListBox1.ListCount + ' Items found'
endif
$PBar1.Value = iif($PBar1.Value < $PBar1.Max,$PBar1.Value + 1,0) ;for progress bar only
Next
$ProgForm.Hide
Endif
$adTextBox1.SetFocus
; $rc = SENDKEYS ("^{END}")
EndFunction
Function Finduser(optional $skip)
select
case $adTextBox1.KeyCode=13 and not $skip
; ********************************************************************
; ***** This is the section that returns the selected username *****
; ***** back to your main form *****
; ***** $ReturnText.text = text of the name *****
; ***** $ReturnLDAP = the ldap string of the selected acct *****
; ********************************************************************
$ADForm.Hide
$adTextBox1.text = $adListBox1.Text
$nameLDAP = TranslateName(1, @domain, 4, $adListBox1.Text, 1)
if $nameLDAP[1] = 0
$ReturnText.text = $adListBox1.Text
$ReturnLDAP = $nameLDAP[0]
endif
case $adTextBox1.KeyCode=40 and not $skip and $adListBox1.ListIndex +1 < $adListBox1.ListCount
$adListBox1.ListIndex = $adListBox1.ListIndex +1
$adTextBox1.text = $adListBox1.Text
$adTextBox1.SetFocus()
$rc = SENDKEYS ("^{END}")
case $TextBox1.KeyCode=38 and not $skip and $adListBox1.ListIndex -1 > 0
$adListBox1.ListIndex = $adListBox1.ListIndex -1
$adTextBox1.text = $adListBox1.Text
$adTextBox1.SetFocus()
$rc = SENDKEYS ("^{END}")
case 1
for $element=0 to $adListBox1.ListCount - 1
if left($adListBox1.List($element),len($adTextBox1.text))=$adTextBox1.text
$adListBox1.ListIndex = $element
$element = $adListBox1.ListCount
endif
next
endselect
EndFunction
Function ListBoxClicked()
$adTextBox1.text = $adListBox1.Text
$adTextBox1.SetFocus()
$rc = SENDKEYS ("^{END}")
EndFunction
Function TranslateName($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0 $ErrorText = "" $ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate") $Error = @error $ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName) $Error = @error $ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName) $Error = @error $ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType) $Error = @error $ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction