Jump to content

ldap and child gui problem


Recommended Posts

i got a problem with retreiving computers using ldap reuqest and i have problem closing the child gui (Check list)

#Include <Constants.au3>
#include <GuiTreeView.au3>
#Include <GuiList.au3>
#include <Array.au3>
#include <File.au3>
#Include <GuiTab.au3>
Opt("TrayIconHide", 1)
Dim $program, $hostlist, $btnExecute, $gui, $tListView

#region Main GUI
;Func MainGUI()
Global $gui, $tGui, $tListView, $ExecStatWin
$gui = GUICreate("Remote - Remote Execution Tool", 400, 300, -1, -1)
$btnExecute = GUICtrlCreateButton("Execute", 205, 243, 90, 30)
GUICtrlSetState(-1, $GUI_DISABLE)
$btnQuit = GUICtrlCreateButton("Quit", 305, 243, 90, 30)
$tabs = GUICtrlCreateTab(5, 0, 390, 234)
$tabHosts = GUICtrlCreateTabItem("Hosts")
$btnPrev1 = GUICtrlCreateButton("Previous", 5, 243, 90, 30)
$btnNext1 = GUICtrlCreateButton("Next", 105, 243, 90, 30)
$hostlist = GUICtrlCreateList("", 10, 27, 290, 201)
$btnAdd = GUICtrlCreateButton("Add", 305, 28, 83, 22)
$btnRemove = GUICtrlCreateButton("Remove", 305, 58, 83, 22)
$btnBrowse = GUICtrlCreateButton("Browse", 305, 88, 83, 22)
$btnClear = GUICtrlCreateButton("Clear", 305, 118, 83, 22)
$btnLoad = GUICtrlCreateButton("Load", 305, 175, 83, 22)
$btnSave = GUICtrlCreateButton("Save", 305, 205, 83, 22)
$tabExecute = GUICtrlCreateTabItem("Execute")
$btnNext2 = GUICtrlCreateButton("Next", 105, 243, 90, 30)
$btnPrev2 = GUICtrlCreateButton("Previous", 5, 243, 90, 30)
$label0 = GUICtrlCreateLabel("* = Optional", 320, 32, 75, 22)
$label1 = GUICtrlCreateLabel("Executable: ", 26, 60, 75, 22)
$program = GUICtrlCreateInput("", 90, 57, 250, 22, $ES_READONLY + $ES_AUTOHSCROLL)
$btnProgram = GUICtrlCreateButton("...", 345, 57, 22, 22)
$label2 = GUICtrlCreateLabel("* Working Dir: ", 16, 100, 80, 22)
$directory = GUICtrlCreateInput("", 90, 97, 250, 22, $ES_READONLY + $ES_AUTOHSCROLL)
$btnDir = GUICtrlCreateButton("...", 345, 97, 22, 22)
$label3 = GUICtrlCreateLabel("* Arguments: ", 22, 140, 80, 22)
$arguments = GUICtrlCreateInput("", 90, 137, 250, 22)
$label4 = GUICtrlCreateLabel("Context: ", 44, 180, 80, 22)
$context = GUICtrlCreateCombo("", 90, 177, 120, 22)
GUICtrlSetData(-1, "Interactive|Non-Interactive|System|Interactive System|Limited", "Interactive")
$btnTestLocal = GUICtrlCreateButton("Test Local", 250, 177, 90, 22)
GUICtrlSetState(-1, $GUI_DISABLE)
$check = GUICtrlCreateButton("Check", 250, 200, 90, 22)
$information = GUICtrlCreateTabItem("Information")
$SystemInfo = GUICtrlCreateButton("SystemInfo", 20, 58, 90, 27)
$btnPrev3 = GUICtrlCreateButton("Previous", 5, 243, 90, 30)
$btnNext3 = GUICtrlCreateButton("Next", 105, 243, 90, 30)
$RDP = GUICtrlCreateTabItem("RDP")
$RDPconsole = GUICtrlCreateButton("RDP", 20, 58, 90, 27)
GUICtrlCreateLabel("Create a RDP session to remote host.", 125, 67)
$VNC = GUICtrlCreateButton("VNC", 20, 100, 90, 27)
GUICtrlCreateLabel("Connect to any VNC Client.", 125, 109)
$btnPrev4 = GUICtrlCreateButton("Previous", 5, 243, 90, 30)
$btnNext4 = GUICtrlCreateButton("Next", 105, 243, 90, 30)
$Status = GUICtrlCreateTabItem("Manage")
$Tasklist = GUICtrlCreateButton("Task List", 260, 58, 90, 27)
$Manage = GUICtrlCreateButton("Manage", 140, 58, 90, 27)
$Explore = GUICtrlCreateButton("Explore", 20, 58, 90, 27)
$btnPrev5 = GUICtrlCreateButton("Previous", 5, 243, 90, 30)
$btnNext5 = GUICtrlCreateButton("Next", 105, 243, 90, 30)
 
GUISetState()

While 1
 $msg = GUIGetMsg()
 If $msg = $btnAdd Then
  $hosttoadd = InputBox("Hostname:", "Enter a hostname.", "", "", 200, 120)
  If $hosttoadd Then
   _GUICtrlListAddItem($hostlist, StringUpper($hosttoadd))
   CheckExec()
  EndIf
 EndIf
If $msg = $btnBrowse Then
  $hosttoadd = BrowseHosts()
  GUISetState(@SW_MINIMIZE)
  GUISetState(@SW_RESTORE)
If $hosttoadd[0] <> "" Then
   For $i = 0 To UBound($hosttoadd) - 1
    _GUICtrlListAddItem($hostlist, $hosttoadd[$i])
   Next
   CheckExec()
EndIf
 EndIf
 If $msg = $btnClear Then
  _GUICtrlListClear($hostlist)
  CheckExec()
 EndIf
 If $msg = $btnDir Then
  $wrkDir = FileSelectFolder("Working Directory", "C:\")
  If $wrkDir <> "" Then GUICtrlSetData($directory, $wrkDir)
 EndIf
 If $msg = $btnExecute Then
  $ExecStatWin = ExecStatusWin()
  GUICtrlSetState($btnExecute, $GUI_DISABLE)
  For $i = 0 To _GUICtrlListCount($hostlist) - 1
   $hostnamevar = _GUICtrlListGetText($hostlist, $i)
   If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then $hostnamevar = "127.0.0.1" 
   If $hostnamevar = "LOCALHOST"  Then $hostnamevar = "127.0.0.1" 
   $execfilevar = GUICtrlRead($program)
   If $execfilevar <> "" Then
    $contextvar = GUICtrlRead($context)
    $wrkdirvar = GUICtrlRead($directory)
    $argsvar = GUICtrlRead($arguments)
    ExecStatus($i, $hostnamevar, "Attempting connection...")
    If Ping($hostnamevar) Then
     ExecStatus($i, $hostnamevar, "Executing...")
     $psexecpath = GenPSEXEC($hostnamevar)
     ExecMethod($psexecpath, $hostnamevar, $execfilevar, $contextvar, $wrkdirvar, $argsvar)
     ExecStatusInfo($i, $hostnamevar)
     FileDelete($psexecpath)
    Else
     ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
    EndIf
   EndIf
  Next
 EndIf
 If $msg = $VNC Then
  vnc()
 EndIf
 If $msg = $RDPconsole Then
  RDPconsole()
 EndIf
 If $msg = $btnLoad Then
  $wrkfile = FileOpenDialog("Load Hostlist", @WorkingDir, "Text files (*.txt)")
  If $wrkfile <> "" Then
   $linecount = _FileCountLines($wrkfile)
   
   If FileReadLine($wrkfile, 1) = "<RemoteIt Hostlist>"  Then
    _GUICtrlListClear($hostlist)
    For $i = 2 To $linecount - 1
     _GUICtrlListAddItem($hostlist, FileReadLine($wrkfile, $i))
    Next
    FileClose($wrkfile)
   Else
    MsgBox(0, "Not a valid host list.", "Please use host lists saved with Remote It.")
   EndIf
   CheckExec()
  EndIf
 EndIf
 If $msg = $SystemInfo Then
  SystemInfo()
 EndIf
 If $msg = $Manage Then
  Manage()
 EndIf
 If $msg = $Explore Then
  Explore()
 EndIf
 
 If $msg = $Tasklist Then
  
 EndIf
 
 If $msg = $check Then

  $joww = GUICreate("Check list", 350, 215)
  $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
  $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
  GUICtrlSetColor(-1, 0x0000C0)
  $displayitem = GUICtrlCreateTreeViewItem("Registry", $treeview)
  GUICtrlSetColor(-1, 0x0000C0)
  $aboutitem = GUICtrlCreateTreeViewItem("Dir", $generalitem)
  $compitem = GUICtrlCreateTreeViewItem("File", $generalitem)
  $resitem = GUICtrlCreateTreeViewItem("Macine", $displayitem)
  $otheritem = GUICtrlCreateTreeViewItem("User", $displayitem)
  $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
  $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
  GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
  $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
  GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization
  GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
  $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
  $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
  $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
  $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)
  GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
  GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold
  GUISetState()

  While 1
   $msg = GUIGetMsg()
   Select
Case $msg = $cancelbutton 

case $msg = $GUI_EVENT_CLOSE


    
    Case $msg = $togglebutton   ; Toggle the bold painting
     If BitAND(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
      GUICtrlSetState($generalitem, 0)
      GUICtrlSetState($displayitem, 0)
     Else
      GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
      GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
     EndIf
    Case $msg = $infobutton
     $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
     If $item = 0 Then
      MsgBox(64, "TreeView Demo", "No item currently selected")
     Else
      $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
      If $text == "" Then
       MsgBox(16, "Error", "Error while retrieving infos about item")
      Else
       MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)  ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item
      EndIf
     EndIf
    Case $msg = $statebutton
     $item = GUICtrlRead($treeview)
     If $item > 0 Then
      $hItem = GUICtrlGetHandle($item)
      GUICtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)
     EndIf
     ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
    Case $msg = $generalitem
     GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
    Case $msg = $aboutitem
     GUICtrlSetState($compinfo, $GUI_HIDE)
     GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
    Case $msg = $compitem
     GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
   EndSelect
  WEnd
 
 
 
 
 
 
 
 
 

 EndIf
 If $msg = $btnNext1 Then GUICtrlSetState($tabExecute, $GUI_SHOW)
 If $msg = $btnPrev1 Then GUICtrlSetState($Status, $GUI_SHOW)
 
 If $msg = $btnPrev2 Then GUICtrlSetState($tabHosts, $GUI_SHOW)
 If $msg = $btnNext2 Then GUICtrlSetState($information, $GUI_SHOW)
 
 If $msg = $btnNext3 Then GUICtrlSetState($RDP, $GUI_SHOW)
 If $msg = $btnPrev3 Then GUICtrlSetState($tabExecute, $GUI_SHOW)
 
 If $msg = $btnNext4 Then GUICtrlSetState($Status, $GUI_SHOW)
 If $msg = $btnPrev4 Then GUICtrlSetState($information, $GUI_SHOW)
 
 If $msg = $btnNext5 Then GUICtrlSetState($tabHosts, $GUI_SHOW)
 If $msg = $btnPrev5 Then GUICtrlSetState($RDP, $GUI_SHOW)
 If $msg = $btnProgram Then
  $exec = FileOpenDialog("Executable", @WorkingDir, "Executables (*.exe)|Registry Files (*.reg)")
  
  If $exec <> "" Then
   GUICtrlSetData($program, $exec)
   GUICtrlSetState($btnTestLocal, $GUI_ENABLE)
   CheckExec()
  EndIf
 EndIf
 If $msg = $btnRemove Then
  $idx = _GUICtrlListSelectedIndex($hostlist)
  If $idx > -1 Then _GUICtrlListDeleteItem($hostlist, $idx)
  CheckExec()
 EndIf
 If $msg = $btnSave Then
  $listcount = _GUICtrlListCount($hostlist)
  If $listcount <> 0 Then
   $wrkfile = FileSaveDialog("Save Hostlist", @DesktopDir, "Text files (*.txt)", 16, "hosts.txt")
   If $wrkfile <> "" Then
    If FileExists($wrkfile) Then FileDelete($wrkfile)
    If StringLeft(StringRight($wrkfile, 4), 1) <> "."  Then $wrkfile = $wrkfile & ".txt" 
    FileWriteLine($wrkfile, "<RemoteIt Hostlist>")
    Local $strExport
    For $i = 0 To $listcount - 1
     FileWriteLine($wrkfile, _GUICtrlListGetText($hostlist, $i))
    Next
    FileWriteLine($wrkfile, "<----------------->")
   EndIf
  EndIf
 EndIf
 If $msg = $btnTestLocal Then
  $hostnamevar = "127.0.0.1" 
  $psexecvar = GenPSEXEC($hostnamevar)
  $execfilevar = GUICtrlRead($program)
  If $execfilevar <> "" Then
   $contextvar = GUICtrlRead($context)
   $wrkdirvar = GUICtrlRead($directory)
   $argsvar = GUICtrlRead($arguments)
   $psexecpath = GenPSEXEC($hostnamevar)
   ExecMethod($psexecvar, $hostnamevar, $execfilevar, $contextvar, $wrkdirvar, $argsvar)
   FileDelete($psexecvar)
  EndIf
 EndIf
 If $msg = $GUI_EVENT_CLOSE Or $msg = $btnQuit Then
  If WinActive("Execution Status") Then
   GUISwitch($tGui)
   GUIDelete()
  Else
   FileDelete(@WindowsDir & "\system32\psexec.exe")
   Exit
  EndIf
 EndIf

WEnd
;EndFunc









#endregion
Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
 Local $idx
 For $idx = $hidestart To $hideend
  GUICtrlSetState($idx, $GUI_HIDE)
 Next
 For $idx = $showstart To $showend
  GUICtrlSetState($idx, $GUI_SHOW)
 Next
EndFunc   ;==>GUIChangeItems
Func CheckExec()
 If GUICtrlRead($program) <> "" And _GUICtrlListCount($hostlist) > 0 Then
  GUICtrlSetState($btnExecute, $GUI_ENABLE)
 Else
  GUICtrlSetState($btnExecute, $GUI_DISABLE)
 EndIf
EndFunc   ;==>CheckExec
Func BrowseHosts($debug = False)
 $domain = GetRootDSE()
 $arrComputers = GetComputers($domain)
 $arrSelectedHosts = DispComputers($arrComputers)
 If $debug <> False Then _ArrayDisplay($arrSelectedHosts)
 Return $arrSelectedHosts
EndFunc   ;==>BrowseHosts
Func Manage()
 
 
 $ExecStatWin = ExecStatusWin()
 For $i = 0 To _GUICtrlListCount($hostlist) - 1
  $hostnamevar = _GUICtrlListGetText($hostlist, $i)
  
  If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then
   $hostnamevar = "127.0.0.1" 
  EndIf
  
  If $hostnamevar = "LOCALHOST"  Then
   $hostnamevar = "127.0.0.1" 
   ExecStatus($i, $hostnamevar, "Attempting connection...")
  EndIf
  
  If Ping($hostnamevar) Then
   ExecStatus($i, $hostnamevar, "Executing...")
   Run(@ComSpec & ' /c ' & "compmgmt.msc /computer=\\" & $hostnamevar, @TempDir, @SW_HIDE)
   ExecStatus($i, $hostnamevar, "Compleet")
  Else
   ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
   
   
  EndIf
 Next
 
EndFunc   ;==>Manage
Func Explore()
 
 $ExecStatWin = ExecStatusWin()
 For $i = 0 To _GUICtrlListCount($hostlist) - 1
  $hostnamevar = _GUICtrlListGetText($hostlist, $i)
  
  If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then
   $hostnamevar = "127.0.0.1" 
  EndIf
  
  If $hostnamevar = "LOCALHOST"  Then
   $hostnamevar = "127.0.0.1" 
   ExecStatus($i, $hostnamevar, "Attempting connection...")
  EndIf
  
  If Ping($hostnamevar) Then
   ExecStatus($i, $hostnamevar, "Executing...")
   Run(@ComSpec & ' /c ' & "start \\" & $hostnamevar & "\C$", @TempDir, @SW_HIDE)
   ExecStatus($i, $hostnamevar, "Compleet")
  Else
   ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
   
   
  EndIf
 Next
 
EndFunc   ;==>Explore
Func SystemInfo()
 
 $ExecStatWin = ExecStatusWin()
 For $i = 0 To _GUICtrlListCount($hostlist) - 1
  $hostnamevar = _GUICtrlListGetText($hostlist, $i)
  
  If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then
   $hostnamevar = "127.0.0.1" 
  EndIf
  
  If $hostnamevar = "LOCALHOST"  Then
   $hostnamevar = "127.0.0.1" 
   ExecStatus($i, $hostnamevar, "Attempting connection...")
  EndIf
  
  If Ping($hostnamevar) Then
   ExecStatus($i, $hostnamevar, "Executing...")
   ShellExecute("msinfo32.exe", " /computer \\" & $hostnamevar)
   ExecStatus($i, $hostnamevar, "Compleet")
  Else
   ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
   
   
  EndIf
 Next
 
 
EndFunc   ;==>SystemInfo
Func DispComputers($arrComputers)
 Dim $tTreeArr[1]
 $tGui = GUICreate("Browse for Hosts", 250, 322, -1, -1, "", "", $gui)
 $tTree = GUICtrlCreateTreeView(5, 5, 235, 258, BitOR(256, 55))
 $tSelectAll = GUICtrlCreateButton("Select All", 85, 270, 75, 20)
 $tDeSelectAll = GUICtrlCreateButton("Deselect All", 165, 270, 75, 20)
 $tOKBtn = GUICtrlCreateButton("OK", 5, 270, 75, 20)
 GUICtrlSetState(-1, $GUI_FOCUS)
 For $i = 0 To UBound($arrComputers) - 1
  $tTreeArr[$i] = GUICtrlCreateTreeViewItem($arrComputers[$i], $tTree)
  ReDim $tTreeArr[$i + 2]
 Next
 $tVarTreeCount = _GUICtrlTreeViewGetCount($tTree)
 GUISetState(@SW_SHOW, $tGui)
 While 1
  $msg = GUIGetMsg()
  If $msg = $tSelectAll Then
   For $i = 0 To $tVarTreeCount - 1
    GUICtrlSetState($tTreeArr[$i], $GUI_CHECKED)
   Next
  EndIf
  If $msg = $tDeSelectAll Then
   For $i = 0 To $tVarTreeCount - 1
    GUICtrlSetState($tTreeArr[$i], $GUI_UNCHECKED)
   Next
  EndIf
  If $msg = $tOKBtn Then
   Local $tStrSelectedHosts
   For $i = 0 To $tVarTreeCount - 1
    If BitAND(GUICtrlRead($tTreeArr[$i]), $GUI_CHECKED) Then
     $tStrSelectedHosts = $tStrSelectedHosts & GUICtrlRead($tTreeArr[$i], 1) & "," 
    EndIf
   Next
   GUIDelete($tGui)
   $tArrSelectedHosts = StringSplit($tStrSelectedHosts, ",")
   _ArrayDelete($tArrSelectedHosts, 0)
   _ArrayDelete($tArrSelectedHosts, UBound($tArrSelectedHosts) - 1)
   Return $tArrSelectedHosts
  EndIf
 WEnd
EndFunc   ;==>DispComputers
Func ExecMethod($psexecloc, $hostname, $execfile, $context, $wrkDir = "", $args = "", $debug = False)
 $strExe = $psexecloc
 $strExe = $strExe & " \\" & $hostname
 Select
  Case $context = "Interactive" 
   $strExe = $strExe & " -i -high " 
  Case $context = "Non-Interactive" 
   $strExe = $strExe & " " 
  Case $context = "System" 
   $strExe = $strExe & " -s " 
  Case $context = "Interactive System" 
   $strExe = $strExe & " -s -i " 
  Case $context = "Limited" 
   $strExe = $strExe & " -l " 
 EndSelect
 $strExe = $strExe & "-d -c -f " 
 If $wrkDir <> "" Then $strExe = $strExe & "-w " & $wrkDir
 $strExe = $strExe & Chr(34) & $execfile & Chr(34)
 If $args <> "" Then $strExe = $strExe & " " & $args
 If $debug <> False Then
  MsgBox(0, "exec cmd", $strExe)
  ClipPut(@ComSpec & " /c " & $strExe & " 2> C:\psexec.Log")
 Else
  RunWait(@ComSpec & " /c " & $strExe & " 2> C:\" & $hostname & "psexec.Log", "", @SW_HIDE)
 EndIf
EndFunc   ;==>ExecMethod
Func ExecStatus($indx, $strHost, $strStatus, $strResult = "")
 _GUICtrlListViewDeleteItem($tListView, $indx)
 _GUICtrlListViewInsertItem($tListView, $indx, $strHost & "|" & $strStatus & "|" & $strResult)
EndFunc   ;==>ExecStatus
Func ExecStatusInfo($indx, $strHost)
 $tmpfile = FileOpen("C:\" & $strHost & "psexec.Log", 0)
 $strStatus = FileRead($tmpfile)
 FileClose($tmpfile)
 FileDelete("C:\" & $strHost & "psexec.Log")
 If StringInStr($strStatus, "Process ID") > 0 Then
  $str = StringRight($strStatus, StringLen($strStatus) - StringInStr($strStatus, "Process ID") + 1)
  $str = StringLeft($str, StringInStr($str, "."))
  ExecStatus($indx, $strHost, "Finished", $str)
  Return
 EndIf
 If StringInStr($strStatus, "error copying") > 0 Then
  ExecStatus($indx, $strHost, "Error copying file to host.", "Failed")
  Return
 EndIf
 ExecStatus($indx, $strHost, "Failed to Execute.", "Failed")
 Return
EndFunc   ;==>ExecStatusInfo
Func ExecStatusWin()
 $tGui = GUICreate("Execution Status", 450, 400, -1, -1, $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX)
 $tListView = GUICtrlCreateListView("Hostname|Status|Result", 0, 0, 448, 380)
 _GUICtrlListViewSetColumnWidth($tListView, 0, 100)
 _GUICtrlListViewSetColumnWidth($tListView, 1, 160)
 _GUICtrlListViewSetColumnWidth($tListView, 2, 100)
 GUISetState(@SW_SHOW, $tGui)
 Return WinGetHandle("Execution Status")
EndFunc   ;==>ExecStatusWin
Func GetComputers($domainname)
 $objComputers = ObjGet("LDAP://CN=Computers," & $domainname)
 Local $strComputers
 For $obj In $objComputers
  $strComputers = $strComputers & $obj.Name & "," 
 Next
 $obj = ""
 $objComputers = ""
 $strComputers = StringLeft($strComputers, StringLen($strComputers) - 1)
 $strComputers = StringReplace($strComputers, "CN=", "")
 $arrComputers = StringSplit($strComputers, ",")
 _ArrayDelete($arrComputers, 0)
 _ArraySort($arrComputers)
 Return $arrComputers
EndFunc   ;==>GetComputers
Func GenPSEXEC($host)
 FileInstall("psexec.exe", "C:\" & $host & "psexec.exe")
 $psexecpath = "C:\" & $host & "psexec.exe" 
 Return $psexecpath
EndFunc   ;==>GenPSEXEC 
Func RDPconsole()
 $ExecStatWin = ExecStatusWin()
 For $i = 0 To _GUICtrlListCount($hostlist) - 1
  $hostnamevar = _GUICtrlListGetText($hostlist, $i)
  
  If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then
   $hostnamevar = "127.0.0.1" 
  EndIf
  
  If $hostnamevar = "LOCALHOST"  Then
   $hostnamevar = "127.0.0.1" 
   ExecStatus($i, $hostnamevar, "Attempting connection...")
  EndIf
  
  If Ping($hostnamevar) Then
   ExecStatus($i, $hostnamevar, "Executing...")
   Run(@ComSpec & ' /c ' & "mstsc.exe /v:" & $hostnamevar, @TempDir, @SW_HIDE)
   ExecStatus($i, $hostnamevar, "Compleet")
  Else
   ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
   
   
  EndIf
 Next
 
 

EndFunc   ;==>RDPconsole
Func GetRootDSE()
 $RootDSE = ObjGet("LDAP://RootDSE")
 Return $RootDSE.get ("DefaultNamingContext")
EndFunc   ;==>GetRootDSE
Func vnc()
 $ExecStatWin = ExecStatusWin()
 For $i = 0 To _GUICtrlListCount($hostlist) - 1
  $hostnamevar = _GUICtrlListGetText($hostlist, $i)
  
  If StringUpper($hostnamevar) = StringUpper(@ComputerName) Then
   $hostnamevar = "127.0.0.1" 
  EndIf
  
  If $hostnamevar = "LOCALHOST"  Then
   $hostnamevar = "127.0.0.1" 
   ExecStatus($i, $hostnamevar, "Attempting connection...")
  EndIf
  
  If Ping($hostnamevar) Then
   ExecStatus($i, $hostnamevar, "Executing...")
   Run("vncviewer.exe " & $hostnamevar)
   WinWaitActive("VNC Authentication")
   ControlSetText("VNC Authentication", "", "Edit1", "remote")
   ExecStatus($i, $hostnamevar, "Compleet")
  Else
   ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed")
   
   
  EndIf
 Next
EndFunc   ;==>vnc
Link to comment
Share on other sites

i got a problem with retreiving computers using ldap reuqest and i have problem closing the child gui (Check list)

Too much code. Strip it down to a short reproducer for the LDAP problem, and another short one to reproduce the child GUI problem.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Too much code. Strip it down to a short reproducer for the LDAP problem, and another short one to reproduce the child GUI problem.

<_<

ldap

Func GetComputers($domainname)
 $objComputers = ObjGet("LDAP://CN=Computers," & $domainname)
 Local $strComputers
 For $obj In $objComputers
  $strComputers = $strComputers & $obj.Name & "," 
 Next
 $obj = ""
 $objComputers = ""
 $strComputers = StringLeft($strComputers, StringLen($strComputers) - 1)
 $strComputers = StringReplace($strComputers, "CN=", "")
 $arrComputers = StringSplit($strComputers, ",")
 _ArrayDelete($arrComputers, 0)
 _ArraySort($arrComputers)
 Return $arrComputers
EndFunc   ;==>GetComputers
Func GenPSEXEC($host)
 FileInstall("psexec.exe", "C:\" & $host & "psexec.exe")
 $psexecpath = "C:\" & $host & "psexec.exe" 
 Return $psexecpath
EndFunc   ;==>GenPSEXEC 



Func GetRootDSE()
 $RootDSE = ObjGet("LDAP://RootDSE")
 Return $RootDSE.get ("DefaultNamingContext")
EndFunc   ;==>GetRootDSEoÝ÷ ÙÈbØ.«­¢+ØÀÌØí©½ÝÜôU%
ÉÑ ÅÕ½Ðí
¡¬±¥ÍÐÅÕ½Ðì°ÌÔÀ°ÈÄÔ¤(ÀÌØíÑÉÙ¥ÜôU%
Ñɱ
ÉÑQÉY¥Ü ذذÄÀÀ°ÄÔÀ°   ¥Ñ=H ÀÌØíQYM}!M   UQQ=9L°ÀÌØíQYM}!M1%9L°ÀÌØíQYM}1%9MQI==P°ÀÌØíQYM}%M   1II=@°ÀÌØíQYM}M!=]M11]eL¤°ÀÌØí]M}a}
1%9Q¤(ÀÌØí¹É±¥Ñ´ôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½Ðí¹É°ÅÕ½Ðì°ÀÌØíÑÉ٥ܤ(U%
ÑɱMÑ
½±½È ´Ä°ÁàÀÀÀÁÀ¤(ÀÌØí¥ÍÁ±å¥Ñ´ôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½ÐíI¥ÍÑÉäÅÕ½Ðì°ÀÌØíÑÉ٥ܤ(U%
ÑɱMÑ
½±½È ´Ä°ÁàÀÀÀÁÀ¤(ÀÌØí½ÕѥѴôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½Ðí¥ÈÅÕ½Ðì°ÀÌØí¹É±¥Ñ´¤(ÀÌØí½µÁ¥Ñ´ôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½Ðí¥±ÅÕ½Ðì°ÀÌØí¹É±¥Ñ´¤(ÀÌØíÉͥѴôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½Ðí5¥¹ÅÕ½Ðì°ÀÌØí¥ÍÁ±å¥Ñ´¤(ÀÌØí½Ñ¡É¥Ñ´ôU%
Ñɱ
ÉÑQÉY¥Ý%Ñ´ ÅÕ½ÐíUÍÈÅÕ½Ðì°ÀÌØí¥ÍÁ±å¥Ñ´¤(ÀÌØíÍÑÉѱ°ôU%
Ñɱ
ÉÑ1° ÅÕ½ÐíQÉY¥Üµ¼ÅÕ½Ðì°ÄäÀ°äÀ°ÄÀÀ°ÈÀ¤(ÀÌØí½Õѱ°ôU%
Ñɱ
ÉÑ1° ÅÕ½ÐíQ¡¥Ì±¥ÑѱÍÉ¥ÁÑ̵½¹ÍÑÑÌÑ¡ÕÍ¥¹½ÑÉ٥ܵ½¹Ñɽ°¸ÅÕ½Ðì°ÄäÀ°ÜÀ°ÄÀÀ°ØÀ¤(U%
ÑɱMÑMÑÑ ´Ä°ÀÌØíU%}!%¤ì!¥ÌÑ¡ÅÕ½Ðí½Õѱ°ÅÕ½ÐìµÑáÐÕÉ¥¹¥¹¥Ñ¥±¥éÑ¥½¸(ÀÌØí½µÁ¥¹¼ôU%
Ñɱ
ÉÑ1° ÅÕ½Ðí9µèÅÕ½ÐìµÀìQµÀì
½µÁÕÑÉ9µµÀì1µÀìÅÕ½Ðí=LèÅÕ½ÐìµÀìQµÀì=MYÉÍ¥½¸µÀì1µÀìÅÕ½ÐíM@èÅÕ½ÐìµÀìQµÀì=MMÉÙ¥A¬°ÄÈÀ°ÌÀ°ÈÀÀ°àÀ¤(U%
ÑɱMÑMÑÑ ´Ä°ÀÌØíU%}!%¤ì!¥ÌÑ¡ÅÕ½Ðí½µÁ¥¹¼ÅÕ½ÐìµÑáÐÕÉ¥¹¥¹¥Ñ¥±¥éÑ¥½¸(U%
Ñɱ
ÉÑ1° ÅÕ½ÐìÅÕ½Ðì°À°ÄÜÀ°ÌÔÀ°È°ÀÌØíMM}MU9-8¤(ÀÌØíѽ±ÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐìµÀíQ½±ÅÕ½Ðì°ÌÔ°ÄàÔ°ÜÀ°ÈÀ¤(ÀÌØí¥¹½ÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐìµÀí%¹¼ÅÕ½Ðì°ÄÀÔ°ÄàÔ°ÜÀ°ÈÀ¤(ÀÌØíÍÑÑÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí
½°¸½áÀ¸ÅÕ½Ðì°ÄÜÔ°ÄàÔ°ÜÀ°ÈÀ¤(ÀÌØí¹±ÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐìµÀí
¹°ÅÕ½Ðì°ÈÐÔ°ÄàÔ°ÜÀ°ÈÀ¤(U%
ÑɱMÑMÑÑ ÀÌØí¹É±¥Ñ´°   ¥Ñ=H ÀÌØíU%}aA9°ÀÌØíU%}  UQQ=8¤¤ìáÁ¹Ñ¡ÅÕ½Ðí¹É°ÅÕ½Ð쵥Ѵ¹Á¥¹Ð¥¸½±(U%
ÑɱMÑMÑÑ ÀÌØí¥ÍÁ±å¥Ñ´°   ¥Ñ=H ÀÌØíU%}aA9°ÀÌØíU%}  UQQ=8¤¤ìáÁ¹Ñ¡ÅÕ½Ðí¥ÍÁ±äÅÕ½Ð쵥Ѵ¹Á¥¹Ð¥¸½±(U%MÑMÑÑ ¤((]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤(M±Ð)
ÍÀÌØíµÍôÀÌØí¹±ÕÑѽ¸()ÍÀÌØíµÍôÀÌØíU%}Y9Q}
1=M((($(
ÍÀÌØíµÍôÀÌØíѽ±ÕÑѽ¸ìQ½±Ñ¡½±Á¥¹Ñ¥¹(%   ¥Ñ9¡U%
ÑɱI ÀÌØí¹É±¥Ñ´¤°ÀÌØíU%} UQQ=8¤Q¡¸(U%
ÑɱMÑMÑÑ ÀÌØí¹É±¥Ñ´°À¤(U%
ÑɱMÑMÑÑ ÀÌØí¥ÍÁ±å¥Ñ´°À¤(±Í(U%
ÑɱMÑMÑÑ ÀÌØí¹É±¥Ñ´°ÀÌØíU%}    UQQ=8¤(U%
ÑɱMÑMÑÑ ÀÌØí¥ÍÁ±å¥Ñ´°ÀÌØíU%}    UQQ=8¤(¹%(
ÍÀÌØíµÍôÀÌØí¥¹½ÕÑѽ¸(ÀÌØí¥Ñ´ôU%
ÑɱI ÀÌØíÑÉ٥ܤìÐÑ¡½¹Ñɽ±%½Ñ¡ÕÉɹÐͱÑÑÉ٥ܥѴ(%ÀÌØí¥Ñ´ôÀQ¡¸(5Í    ½à ØаÅÕ½ÐíQÉY¥Üµ¼ÅÕ½Ðì°ÅÕ½Ðí9¼¥Ñ´ÕÉɹѱäͱÑÅÕ½Ðì¤(±Í(ÀÌØíÑáÐôU%
ÑɱI ÀÌØí¥Ñ´°Ä¤ìÐÑ¡ÑáнѡÑÉ٥ܥѴ(%ÀÌØíÑáÐôôÅÕ½ÐìÅÕ½ÐìQ¡¸(5Í   ½à ÄØ°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½ÐíÉɽÈÝ¡¥±ÉÑÉ¥Ù¥¹¥¹½Ì½ÕХѴÅÕ½Ðì¤(±Í(5Í  ½à ØаÅÕ½ÐíQÉY¥Üµ¼ÅÕ½Ðì°ÅÕ½Ðí
ÕÉɹХѴͱѥÌèÅÕ½ÐìµÀìÀÌØíÑáФìÀÌØíÙµÍlÁt½¹Ñ¥¹ÌÑ¡ÑáйÀÌØíÙµÍlÅtÑ¡ÍÑÑٱսѡÑÉ٥ܥѴ(¹%(¹%(
ÍÀÌØíµÍôÀÌØíÍÑÑÕÑѽ¸(ÀÌØí¥Ñ´ôU%
ÑɱI ÀÌØíÑÉ٥ܤ(%ÀÌØí¥Ñ´ÐìÀQ¡¸(ÀÌØí¡%Ñ´ôU%
ÑɱÑ!¹± ÀÌØí¥Ñ´¤(U%
ÑɱM¹5Í ÀÌØíÑÉ٥ܰÀÌØíQY5}aA9°ÀÌØíQY}Q=1°ÀÌØí¡%Ñ´¤(¹%(ìQ¡½±±½Ý¥¹¥ÑµÌÝ¥±°¡¥Ñ¡½Ñ¡È±±Ì ÅÍйɹÁɵÑȤ¹Ñ¡¸Í¡½ÜÑ¡Ìäí½Ý¸Ìäì±±Ì ÍɹÑÑ ÁɵÑȤ(
ÍÀÌØíµÍôÀÌØí¹É±¥Ñ´(U%
¡¹%ÑµÌ ÀÌØí½Õѱ°°ÀÌØí½µÁ¥¹¼°ÀÌØíÍÑÉѱ°°ÀÌØíÍÑÉѱ°¤(
ÍÀÌØíµÍôÀÌØí½ÕѥѴ(U%
ÑɱMÑMÑÑ ÀÌØí½µÁ¥¹¼°ÀÌØíU%}!%¤(U%
¡¹%ÑµÌ ÀÌØíÍÑÉѱ°°ÀÌØíÍÑÉѱ°°ÀÌØí½Õѱ°°ÀÌØí½Õѱ°¤(
ÍÀÌØíµÍôÀÌØí½µÁ¥Ñ´(U%
¡¹%ÑµÌ ÀÌØíÍÑÉѱ°°ÀÌØí½Õѱ°°ÀÌØí½µÁ¥¹¼°ÀÌØí½µÁ¥¹¼¤(¹M±Ð(]¹
Link to comment
Share on other sites

Thanks for reducing the target load...

This works fine for me on my domain. What is your issue?

#include <array.au3>

$sDomain = "dc=subdomain,dc=domain,dc=com" 
$avComps = GetComputers($sDomain)
_ArrayDisplay($avComps, "Debug: $avComps")

Func GetComputers($domainname)
    $objComputers = ObjGet("LDAP://CN=Computers," & $domainname)
    Local $strComputers
    For $obj In $objComputers
        $strComputers = $strComputers & $obj.Name & "," 
    Next
    $obj = ""
    $objComputers = ""
    $strComputers = StringLeft($strComputers, StringLen($strComputers) - 1)
    $strComputers = StringReplace($strComputers, "CN=", "")
    $arrComputers = StringSplit($strComputers, ",")
    _ArrayDelete($arrComputers, 0)
    _ArraySort($arrComputers)
    Return $arrComputers
EndFunc   ;==>GetComputers

<_<

P.S. Try again on the child GUI reproducer. It has tons of useless code in it, doesn't compile, doesn't all used functions, doesn't have required includes, etc., etc., etc. Trim it down to just a simple parent GUI and a child GUI with the issue (whatever that is).

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

i fiexed the child gui now i only need the ldap request

It's good you figured out the GUI issue, which often happens when you try to reduce the extraneous code to show JUST the problem to somebody else -- you end up seeing the problem yourself. That's one of the reasons for requesting a short reproducer script that can actually be run to show the symptom.

The error indicates your LDAP address failed. There is probably a typo or syntax error in it. You can test for the problem and see the effective lookup being attempted this way:

Func GetComputers($domainname)
    $sLDAP = "LDAP://CN=Computers," & $domainname
    ConsoleWrite("Debug:  LDAP path = " & $sLDAP & @LF)
    $objComputers = ObjGet($sLDAP)
    If Not IsObj($objComputers) Then
        ConsoleWrite("Debug:  LDAP lookup failed." & @LF)
        Return 0
    Else
        ConsoleWrite("Debug:  LDAP lookup succeeded." & @LF)
    EndIf
    
    Local $strComputers
    For $obj In $objComputers
        $strComputers = $strComputers & $obj.Name & ","
    Next
    
    ; ...rest of the function
    
EndFunc

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...