KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Split Container and AD

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
maciep
KiXforms Regular
KiXforms Regular


Joined: 01 May 2003
Posts: 43
Location: Pittsburgh,PA

PostPosted: Thu May 05, 2005 3:21 pm    Post subject: Split Container and AD Reply with quote

I just threw together this "Proof of Concept" script using the Split Container. The first Panel contains a Treeview and the second Panel contains a listview. As of right now it is like the very-poor-man's version of AD Users and Computers.

If anyone wants to expand on it, have at it. I'll probably do more with this in the future myself. (KiXforms ver 2.46)

Code:

Break On
$Sys = createobject("Kixtart.System")

;**********************************************
; The main form. 
;**********************************************
; Create the form
$Form = $Sys.Form
$Form.Size = 600,600
$Form.Visible = (not 0)
$Form.Text = "Split Container Test"

;----------------------------------------------
; AD GroubBox
;----------------------------------------------
$scMain = $Form.Controls.SplitContainer()
$scMain.Location = 15,15
$scMain.Size = 350,350
$scMain.Text = "Select a container"
$scMain.Dock = "Fill"
$scMain.Panel1.Visible = 1

$trvAD = $scMain.Panel1.Controls.TreeView()
$trvAD.Size = 300,300
$trvAD.Location = 20,20
$trvAD.OnBeforeExpand = "OnBeforeExpand()"
$trvAD.OnAfterSelect = "OnAfterSelect()"

$lvView = $scMain.Panel2.Controls.ListView
$lvView.Size = 300,300
$lvView.Location = 2,20
$lvCol1 = $lvView.Columns.Add("Object Name")
$lvCol2 = $lvView.Columns.Add("Ojbect Type")
$lvView.OnDoubleClick= "LVDoubleClick()"

InitAD()

While $Form.Visible
 $=Execute($Form.DoEvents)
Loop
Exit 1


;************************* Functions **************************

function InitAD()
   dim $rootDSE,$strDomain,$p, $t
   $rootDSE = getobject("LDAP://RootDSE")
   $strDomain = $rootDSE.Get("defaultNamingContext")
   $p = $trvAD.Nodes.Add(join(split(join(split($strDomain,"DC="),""), ","),"."))
   $p.Tag = $strDomain
   $t = $p.Nodes.Add("")
endfunction

;-------------------------------------------------------------

function OnBeforeExpand()
   dim $path, $filter, $root
   dim $cont, $t, $b
   if $trvAD.EventNode.Nodes.Count = 1
      if $trvAD.EventNode.Nodes(0).Text = ""
         $Form.Cursor = 11
         $trvAD.EventNode.Nodes.Remove($trvAD.EventNode.Nodes(0))
         $path = $trvAD.EventNode.Tag
         $filter = "Container", "OrganizationalUnit"
         $root = getobject("LDAP://" + $path)
         $root.Filter = $filter
         for each $cont in $root
            $t = $trvAD.EventNode.Nodes.Add(split($cont.Name,"=")[1])
            $t.Tag = $cont.distinguishedName
            $b = $t.Nodes.Add("")
         next
        $Form.Cursor = 1
     endif
   endif
   $trvAD.EventNode.Expand()
endfunction

;-------------------------------------------------------------

function OnAfterSelect()
   dim $path, $filter, $root
   dim $cont, $t, $b
   $lvView.Items.Clear()
   $Form.Cursor = 11
   $path = $trvAD.EventNode.Tag
   $root = getobject("LDAP://" + $path)
   for each $cont in $root
      $new = $lvView.Items.Add(split($cont.Name,"=")[1])
      $new.SubItems(1).text = $cont.Class
      $new.Tag = $Sys.Object
      $new.Tag.dn = $cont.distinguishedName
      $new.Tag.Parent = $trvAD.EventNode
      $new.Tag.IsContainer = ($cont.Class = "OrganizationalUnit" or $cont.Class = "Container")
   next
   $Form.Cursor = 1
endfunction

;-------------------------------------------------------------

function LVDoubleClick()
   dim $found, $temp
   if not $lvView.FocusedItem
      exit 0
   endif
   $item = $lvView.FocusedItem
   if not $item.tag.IsContainer
      exit 0
   endif

   $trvAD.EventNode = $item.Tag.Parent
   OnBeforeExpand()
   $found = 0
   for  $j = 0 to $trvAD.EventNode.Nodes.Count-1
      if $trvAD.EventNode.Nodes($j).tag = $item.tag.dn and not $found
         $temp = $j
         $found = 1
      endif
   next
   $trvAD.SelectedNode = $trvAD.EventNode.Nodes($temp)   
endfunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group