bluechipps Posted May 20, 2009 Share Posted May 20, 2009 (edited) here ya go expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstants.au3> #include <GuiTreeView.au3> #Include <GuiListView.au3> #Include <GuiListBox.au3> #include <Array.au3> #include <File.au3> Opt("TrayIconHide", 1) Dim $program, $hostlist, $btnExecute, $gui, $tListView Global Const $Cursor_ARROW = 2 Global Const $wbemFlagReturnImmediately = 0x10 Global Const $wbemFlagForwardOnly = 0x20 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") $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") $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") $Delltag = GUICtrlCreateButton("DELL TAG", 20, 38, 90, 27) GUICtrlCreateLabel("Retrieve(s) a DELL Service TAG.", 125, 45) $SystemInfo = GUICtrlCreateButton("SystemInfo", 20, 70, 90, 27) GUICtrlCreateLabel("Retrieve(s) a information list from remote host.", 125, 77) $Software = GUICtrlCreateButton("Software", 20, 102, 90, 27) GUICtrlCreateLabel("Retrieve(s) a software list from remote host.", 125, 109) $hardware = GUICtrlCreateButton("Hardware", 20, 134, 90, 27) GUICtrlCreateLabel("Retrieve(s) a hardware list from remote host.", 125, 141) $Serials = GUICtrlCreateButton("Serials", 20, 166, 90, 27) GUICtrlCreateLabel("Retrieve(s) software serials from remote host.", 125, 173) $RDP = GUICtrlCreateTabItem("RDP") $RDPconsole = GUICtrlCreateButton("RDP",20, 38, 90, 27) GUICtrlCreateLabel("Create a RDP session to remote host.", 125, 45) $VNC = GUICtrlCreateButton("VNC", 20, 70, 90, 27) GUICtrlCreateLabel("Connect to any VNC Client.", 125, 77) $Status = GUICtrlCreateTabItem("Manage") $Tasklist = GUICtrlCreateButton("Task List", 20, 38, 90, 27) GUICtrlCreateLabel("View/change the tasklist with all made orders.", 125, 45) $Manage = GUICtrlCreateButton("Manage", 20, 70, 90, 27) GUICtrlCreateLabel("Manage the user(s) Computer(s).", 125, 77) $Explore = GUICtrlCreateButton("Explore", 20, 102, 90, 27) GUICtrlCreateLabel("Explore the user(s) local HD('s).", 125, 109) $Discontinued = GUICtrlCreateButton("Discontinued", 20, 134, 90, 27) GUICtrlCreateLabel("List from computer(s) if the update didn't continued", 125, 141) $Status = GUICtrlCreateTabItem("Status") $shutdown = GUICtrlCreateButton("Shutdown", 20, 38, 90, 27) GUICtrlCreateLabel("Send request shutdown remote host.", 125, 45) $Restart = GUICtrlCreateButton("Restart", 20, 70, 90, 27) GUICtrlCreateLabel("Send request restart remote host.", 125, 77) $Wol = GUICtrlCreateButton("WOL", 20, 102, 90, 27) GUICtrlCreateLabel("Send request Wake On Lan remote host.", 125, 109) $Clientstatus = GUICtrlCreateButton("Status", 20, 134, 90, 27) GUICtrlCreateLabel("Retrieve(s) list with online and Ofline computers.", 125, 141) GUISetState() While 1 $msg = GUIGetMsg() 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 If $msg = $btnAdd Then $hosttoadd = InputBox("Hostname:", "Enter a hostname.", "", "", 200, 120) If $hosttoadd Then _GUICtrlListBox_AddString($hostlist, StringUpper($hosttoadd)) CheckExec() EndIf EndIf If $msg = $btnBrowse Then _Main() EndIf If $msg = $btnClear Then _GUICtrlListBox_ResetContent($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 _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 _GUICtrlListBox_ResetContent($hostlist) For $i = 2 To $linecount - 1 _GUICtrlListBox_AddString($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 GUICreate("Check list", 350, 215) $checkCNRegistry = GUICtrlCreateCheckbox ("Registry", 10, 10, 120, 20) $checkCNFile = GUICtrlCreateCheckbox ("File", 70, 10, 120, 20) $checkCNFolder = GUICtrlCreateCheckbox ("Folder", 130, 10, 120, 20) GUISetState() While 2 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete() ExitLoop EndSelect WEnd EndIf 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 = _GUICtrlListBox_GetCurSel($hostlist) If $idx > -1 Then _GUICtrlListBox_DeleteString($hostlist, $idx) CheckExec() EndIf If $msg = $btnSave Then $listcount = _GUICtrlListBox_GetCount($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, _GUICtrlListBox_GetText($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 WEnd Func CheckExec() If GUICtrlRead($program) <> "" And _GUICtrlListBox_GetCount($hostlist) > 0 Then GUICtrlSetState($btnExecute, $GUI_ENABLE) Else GUICtrlSetState($btnExecute, $GUI_DISABLE) EndIf EndFunc;==>CheckExec Func Manage() $ExecStatWin = ExecStatusWin() For $i = 0 To _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 = _GUICtrlTreeView_GetCount($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 = "") _GUICtrlListView_DeleteItem($tListView, $indx) _GUICtrlListView_InsertItem($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) _GUICtrlListView_SetColumnWidth($tListView, 0, 100) _GUICtrlListView_SetColumnWidth($tListView, 1, 160) _GUICtrlListView_SetColumnWidth($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 _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 _GUICtrlListBox_GetCount($hostlist) - 1 $hostnamevar = _GUICtrlListBox_GetText($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 $iName = "winvnc" $Computer = $hostnamevar ExecStatus($i, $hostnamevar, "Executing...") _ServStart($iName, $Computer) Run("vncviewer.exe " & $hostnamevar) WinWaitActive("VNC Authentication", 5000) ControlSetText("VNC Authentication", "", "Edit1", "remote") ExecStatus($i, $hostnamevar, "Compleet") Else ExecStatus($i, $hostnamevar, "Failed to ping...", "Failed") EndIf Next EndFunc;==>vnc Func _ServStart($iName, $Computer = ".") $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2") $sItems = $Service.ExecQuery("Select * from Win32_Service Where State = 'Stopped' ") For $objService in $sItems If $objService.Name == $iName Then $objService.StartService($objService.Name) Return EndIf Next Return SetError(-1) EndFunc Func _Main() Local $s_Machine, $t_input = "", $num_pcs = 0, $item_num = 0 Local $Title = "Computer list", $MAIN_WINDOW Local $Domain, $filter, $filters, $win_state, $Retrieve_Method Local $exititem Local $Domainitem, $Filtermenu, $Filteritem, $PingTimeOutitem, $FilterIPitem Local $ib_search, $Btn_Search, $Btn_Exit, $i_TimeOut Local $lv_pcs, $lv_pcs_contextmenu, $lv_pcs_contextRefresh, $lv_pcs_contextPopulate Local $lv_pcs_pslist_taskmodetree, $lv_pcs_pslist_taskmode, $lv_pcs_pslist Local $tabs, $tab_pids, $tab_hotfixes Local $lv_allsoftware, $lv_allsoftware_contextmenu, $lv_allsoftware_contextRefresh Local $lv_pid, $lv_pid_contextmenu, $lv_pid_contextKill, $lv_pid_contextRefresh Local $Status, $dll, $msg, $MOUSE_POS, $explore_with, $eb_system Local $tab_loggedin, $lv_loggedin, $tab_drives, $lv_drives, $lv_drives_contextmenu, $lv_drives_contextExplore Local $tab_services, $lv_services, $lv_services_contextmenu, $lv_service_stop, $lv_service_contextRefresh, $lv_service_start Local $lv_service_pause, $lv_service_resume, $lv_service_delete Local $lv_service_startmode, $lv_service_startmodeBoot, $lv_service_startmodeSystem, $lv_service_startmodeAutomatic Local $lv_service_startmodeManual, $lv_service_startmodeDisabled Local $configmenuRetrieveMethods, $ldapitem, $netvitem, $IP_Range = "", $Use_IPRange #endregion **** end variable declares ***** TCPStartup() $Domain = "nea-group.intern" $filter = "*" $Retrieve_Method = "LDAP" $explore_with = "iexplore" $i_TimeOut = 4 $filters = StringSplit($filter, "|") $MAIN_WINDOW = GUICreate($Title, 280, 560, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) $lv_pcs = GUICtrlCreateListView("Machine|IP Address|ID", 0, 0, 276, 460, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER)) GUICtrlSendMsg($lv_pcs, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetColumnWidth ($lv_pcs, 0, 100) _GUICtrlListView_SetColumnWidth ($lv_pcs, 1, 120) _GUICtrlListView_HideColumn ($lv_pcs, 2) $lv_pcs_contextmenu = GUICtrlCreateContextMenu($lv_pcs) GUISetState() If Not StringInStr($Domain, "YOUR-DOMAIN") Then If $Retrieve_Method = "LDAP" Then _RetrieveComputersLdap($lv_pcs, $Domain, $filters, $Status, $i_TimeOut, _ $lv_allsoftware, $lv_pid, $lv_drives, $lv_loggedin, $eb_system, $IP_Range) Else EndIf EndIf GUICtrlSetState($ib_search, $GUI_FOCUS) $dll = DllOpen("user32.dll") While 1 $msg = GUIGetMsg() $win_state = WinGetState($MAIN_WINDOW) Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem ExitLoop Case $msg = $Filteritem _ConfigFilters($filter, $MAIN_WINDOW) Case $msg = $FilterIPitem _ConfigIpRange($IP_Range, $Use_IPRange, $MAIN_WINDOW) Case $msg = $ldapitem If BitAND(GUICtrlRead($ldapitem), $GUI_CHECKED) Then $Retrieve_Method = "LDAP" GUICtrlSetState($netvitem, $GUI_UNCHECKED) EndIf Case $msg = $PingTimeOutitem _ConfigPingTimeOut($i_TimeOut, $MAIN_WINDOW) EndSelect WEnd DllClose($dll) EndFunc;==>_Main Func _RetrieveComputersLdap(ByRef $h_listview, ByRef $Domain, ByRef $filters, ByRef $pc_status, ByRef $ping_timeout, _ ByRef $lv_allsoftware, ByRef $lv_pid, ByRef $lv_drives, ByRef $lv_loggedin, ByRef $eb_system, $IP_Range = "") Local $lv_item, $num_pcs = 1, $inFilter _LockAndWait() GUICtrlSetData($eb_system, "") _GUICtrlListView_DeleteAllItems ($lv_allsoftware) _GUICtrlListView_DeleteAllItems ($lv_pid) _GUICtrlListView_DeleteAllItems ($lv_drives) _GUICtrlListView_DeleteAllItems ($lv_loggedin) _GUICtrlListView_DeleteAllItems ($h_listview) _GUICtrlListView_DeleteAllItems ($h_listview) _GUICtrlListBox_ResetContent($hostlist) _ResetLockWait() _GUICtrlListView_SetColumnWidth ($h_listview, 1, 140) _GUICtrlListView_HideColumn ($h_listview, 2) Local $ObjDomain = ObjGet("WinNT://" & $Domain) Local $ip_address, $pc_name For $Object In $ObjDomain $ip_address = "" If $Object.class = "Computer" Then $pc_name = $Object.Name $inFilter = 0 If $filters[0] = 1 And $filters[1] = "*" Then $inFilter = 1 Else For $x = 1 To $filters[0] If StringUpper(StringMid($pc_name, 1, StringLen($filters[$x]))) = StringUpper($filters[$x]) Then $inFilter = 1 ExitLoop EndIf Next EndIf If $inFilter Then If IsArray($IP_Range) Then For $x = 1 To $IP_Range[0] Local $strIP = StringSplit(TCPNameToIP($pc_name), ".") Local $low_r = StringSplit($IP_Range[$x], "-") Local $high_r = $low_r[2] $low_r = StringSplit($low_r[1], ".") If (Int($strIP[1]) = Int($low_r[1]) And Int($strIP[2]) = Int($low_r[2]) And Int($strIP[3]) = Int($low_r[3])) And _ (Int($strIP[4]) >= Int($low_r[4]) And Int($strIP[4]) <= Int($high_r)) Then $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview) GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item) _SetStatus($h_listview, _GUICtrlListView_GetItemCount ($h_listview) - 1, $pc_status, $ping_timeout) _ReduceMemory() GUICtrlSetData($pc_status, "Machines: " & $num_pcs) $num_pcs += 1 ExitLoop EndIf Next Else $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview) GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item) _SetStatus($h_listview, _GUICtrlListView_GetItemCount ($h_listview) - 1, $pc_status, $ping_timeout) _ReduceMemory() GUICtrlSetData($pc_status, "Machines: " & $num_pcs) $num_pcs += 1 EndIf EndIf EndIf Next _GUICtrlListView_SetColumnWidth ($h_listview, 0, 140) _GUICtrlListView_SetColumnWidth ($h_listview, 1, 100) _GUICtrlListView_HideColumn ($h_listview, 2) GUISetCursor($Cursor_ARROW, 1) EndFunc;==>_RetrieveComputersLdap Func _SetStatus(ByRef $lv_listview, $index, ByRef $Status, ByRef $ping_length) Local $pc_name = _GUICtrlListView_GetItemText ($lv_listview, $index, 0) Local $ip_address = '', $ping_time If $ping_length Then $ping_time = Ping($pc_name, $ping_length) If $ping_time Then Local $lv_item = _GUICtrlListView_GetItemText ($lv_listview, $index, 2) $ip_address = TCPNameToIP($pc_name) GUICtrlSetData($lv_item, $pc_name & "|" & $ip_address & "|" & $lv_item) _ReduceMemory() Return 1 Else Local $lv_item = _GUICtrlListView_GetItemText ($lv_listview, $index, 2) If Ping($lv_item,250) Then GUICtrlSetData($lv_item, $pc_name & "|" &TCPNameToIP($pc_name)& "|" & $lv_item) Else GUICtrlSetData($lv_item, $pc_name & "|" &"---OFFLINE---"& "|" & $lv_item) EndIf EndIf EndIf _ReduceMemory() Return 0 EndFunc;==>_SetStatus Func _GetRole(ByRef $s_pc, ByRef $Status) Local $objWMIService, $colComputer, $objComputer $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $s_pc & "\root\cimv2") If @error Then GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc) Return EndIf $colComputer = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If @error Then GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc) Return EndIf For $objComputer In $colComputer If Int($objComputer.DomainRole) = 1 Then GUICtrlSetData($Status, $s_pc & " is WorkStation") ElseIf Int($objComputer.DomainRole) = 3 Then GUICtrlSetData($Status, $s_pc & " is Server") ElseIf Int($objComputer.DomainRole) = 4 Then GUICtrlSetData($Status, $s_pc & " is Backup Domain Controller") ElseIf Int($objComputer.DomainRole) = 5 Then GUICtrlSetData($Status, $s_pc & " is Primary Domain Controller") Else GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc) EndIf Return $objComputer.DomainRole Next EndFunc;==>_GetRole Func _ConfigPingTimeOut(ByRef $i_TimeOut, ByRef $MAIN_WINDOW) GUISetState(@SW_DISABLE, $MAIN_WINDOW) Local $Save, $LABEL, $CLOSE, $TimeOut_msg, $TimeOut_Window $TimeOut_Window = GUICreate("Ping Time Out Config", 340, 140, -1, -1, -1, -1, $MAIN_WINDOW) #Region --- CodeWizard generated code Start --- If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD GUISetBkColor($Cadet_Blue_3) #EndRegion --- CodeWizard generated code End --- GUICtrlCreateLabel("Ping Time Out (Milliseconds, 0 = no ping)", 10, 10, 320, 20, $ES_CENTER) Local $TimeOut_input = GUICtrlCreateInput($i_TimeOut, 90, 40, 150, 20, $ES_NUMBER) $Save = GUICtrlCreateButton("Save", 40, 100, 120, 25) $CLOSE = GUICtrlCreateButton("Close", 180, 100, 120, 25) GUISetState() Do $TimeOut_msg = GUIGetMsg() Select Case $TimeOut_msg = $Save $i_TimeOut = Int(GUICtrlRead($TimeOut_input)) IniWrite(@ScriptDir & '\AdminTool.ini', "Ping", "TimeOut", $i_TimeOut) Case $TimeOut_msg = $CLOSE ExitLoop EndSelect Until $TimeOut_msg = $GUI_EVENT_CLOSE GUIDelete($TimeOut_Window) GUISetState(@SW_ENABLE, $MAIN_WINDOW) GUISetState(@SW_SHOW, $MAIN_WINDOW) EndFunc;==>_ConfigPingTimeOut Func _ConfigFilters(ByRef $s_filter, ByRef $MAIN_WINDOW) GUISetState(@SW_DISABLE, $MAIN_WINDOW) Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state Local $lv_filters, $a_filter, $x, $filter_input, $Add, $Delete $Filter_Window = GUICreate("Filter Config", 300, 220, -1, -1, -1, -1, $MAIN_WINDOW) #Region --- CodeWizard generated code Start --- If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD GUISetBkColor($Cadet_Blue_3) #EndRegion --- CodeWizard generated code End --- GUICtrlCreateLabel('PC Name Filter', 20, 10, 250, 20) GUICtrlCreateLabel("All Example: *", 20, 25, 250, 20) GUICtrlCreateLabel("Example: Z", 20, 40, 250, 20) $lv_filters = GUICtrlCreateListView("Filters", 20, 70, 100, 100, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER)) GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) _GUICtrlListView_SetColumnWidth ($lv_filters, 0, 90) $a_filter = StringSplit($s_filter, "|") For $x = 1 To $a_filter[0] GUICtrlCreateListViewItem($a_filter[$x], $lv_filters) Next $filter_input = GUICtrlCreateInput("", 140, 70, 120, 20) $Add = GUICtrlCreateButton("Add", 140, 100, 120, 25) $Delete = GUICtrlCreateButton("Delete", 140, 130, 120, 25) GUICtrlSetState($Delete, $GUI_DISABLE) $Save = GUICtrlCreateButton("Save", 20, 190, 120, 25) $CLOSE = GUICtrlCreateButton("Close", 160, 190, 120, 25) GUISetState() Do $filter_msg = GUIGetMsg() Select Case $filter_msg = $Save If _GUICtrlListView_GetItemCount ($lv_filters) > 0 Then $s_filter = "" For $x = 0 To _GUICtrlListView_GetItemCount ($lv_filters) - 1 $s_filter = $s_filter & "|" & _GUICtrlListView_GetItemText ($lv_filters, $x, 0) Next $s_filter = StringTrimLeft($s_filter, 1) IniWrite(@ScriptDir & '\AdminTool.ini', "Workstations", "filter", $s_filter) EndIf Case $filter_msg = $Delete _GUICtrlListView_DeleteItemsSelected ($lv_filters) GUICtrlSetState($Delete, $GUI_DISABLE) Case $filter_msg = $Add If StringLen(GUICtrlRead($filter_input)) Then GUICtrlCreateListViewItem(GUICtrlRead($filter_input), $lv_filters) Case $filter_msg = $CLOSE ExitLoop Case $filter_msg = $GUI_EVENT_PRIMARYDOWN $win_state = WinGetState($Filter_Window) If BitAND($win_state, 8) And BitAND($win_state, 2) Then If _GUICtrlListView_GetNextItem ($lv_filters) <> $LV_ERR Then GUICtrlSetState($Delete, $GUI_ENABLE) EndIf EndIf EndSelect Until $filter_msg = $GUI_EVENT_CLOSE GUIDelete($Filter_Window) GUISetState(@SW_ENABLE, $MAIN_WINDOW) GUISetState(@SW_SHOW, $MAIN_WINDOW) EndFunc;==>_ConfigFilters Func _ConfigIpRange(ByRef $a_IPRange, ByRef $Use_IPRange, ByRef $MAIN_WINDOW) GUISetState(@SW_DISABLE, $MAIN_WINDOW) Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state, $ip, $nCurEdit = 0, $ip_tmp Local $lv_filters, $s_filter, $x, $filter_input[5], $filter_use, $Add, $Delete, $ip_len, $current_control $Filter_Window = GUICreate("IP Range Config", 360, 220, -1, -1, -1, -1, $MAIN_WINDOW) #Region --- CodeWizard generated code Start --- If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD GUISetBkColor($Cadet_Blue_3) #EndRegion --- CodeWizard generated code End --- GUICtrlCreateLabel('Range(s) of IP Filter', 20, 10, 250, 20) $lv_filters = GUICtrlCreateListView("Start|End", 20, 40, 140, 140, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER)) GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) _GUICtrlListView_SetColumnWidth ($lv_filters, 0, 90) If IsArray($a_IPRange) Then For $x = 1 To $a_IPRange[0] $s_filter = StringReplace($a_IPRange[$x], "-", "|") GUICtrlCreateListViewItem($s_filter, $lv_filters) Next EndIf $filter_use = GUICtrlCreateCheckbox("Use IP Range Inclusion Filter(s)", 170, 40) If $Use_IPRange Then GUICtrlSetState($filter_use, $GUI_CHECKED) $filter_input[0] = GUICtrlCreateInput("", 170, 70, 30, 20, $ES_NUMBER) GUICtrlSetLimit($filter_input[0], 3, 1) $filter_input[1] = GUICtrlCreateInput("", 205, 70, 30, 20, $ES_NUMBER) GUICtrlSetLimit($filter_input[1], 3, 1) $filter_input[2] = GUICtrlCreateInput("", 240, 70, 30, 20, $ES_NUMBER) GUICtrlSetLimit($filter_input[2], 3, 1) $filter_input[3] = GUICtrlCreateInput("", 275, 70, 30, 20, $ES_NUMBER) GUICtrlSetLimit($filter_input[3], 3, 1) GUICtrlCreateLabel("-", 310, 70, 10, 20) $filter_input[4] = GUICtrlCreateInput("", 320, 70, 30, 20, $ES_NUMBER) GUICtrlSetLimit($filter_input[4], 3, 1) $Add = GUICtrlCreateButton("Add", 170, 100, 120, 25) GUICtrlSetState($Add, $GUI_DISABLE) $Delete = GUICtrlCreateButton("Delete", 170, 130, 120, 25) GUICtrlSetState($Delete, $GUI_DISABLE) $Save = GUICtrlCreateButton("Save", 50, 190, 120, 25) $CLOSE = GUICtrlCreateButton("Close", 190, 190, 120, 25) GUISetState() GUICtrlSetState($filter_input[0], $GUI_FOCUS) Do $filter_msg = GUIGetMsg() $ip = _IsPressedMod() If $ip > 0 Then $ip_tmp = GUICtrlRead($filter_input[$nCurEdit]) If (StringLen($ip_tmp) = 3) And not ($ip = 8) Then If $nCurEdit = UBound($filter_input) - 1 Then ContinueLoop $nCurEdit = $nCurEdit + 1 GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS) ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then If $nCurEdit = 0 Then ContinueLoop $nCurEdit = $nCurEdit - 1 Sleep ( 200 ); make sure buffer clears GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS) GUICtrlSetData($filter_input[$nCurEdit], GUICtrlRead($filter_input[$nCurEdit])) EndIf EndIf ; set current selection in case user hit tab key or used mouse to select input $current_control = ControlGetFocus($Filter_Window) Select Case $current_control = "Edit1" And $nCurEdit > 0 $nCurEdit = 0 Case $current_control = "Edit2" And $nCurEdit <> 1 $nCurEdit = 1 Case $current_control = "Edit3" And $nCurEdit <> 2 $nCurEdit = 2 Case $current_control = "Edit4" And $nCurEdit <> 3 $nCurEdit = 3 Case $current_control = "Edit5" And $nCurEdit < 4 $nCurEdit = 4 EndSelect Select Case $filter_msg = $Save If BitAND(GUICtrlRead($filter_use), $GUI_CHECKED) Then $Use_IPRange = 1 Else $Use_IPRange = 0 EndIf IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Filter", "Use", $Use_IPRange) IniDelete(@ScriptDir & '\AdminTool.ini', "IP-Ranges") If _GUICtrlListView_GetItemCount ($lv_filters) > 0 Then ReDim $a_IPRange[_GUICtrlListView_GetItemCount ($lv_filters) + 1] $a_IPRange[0] = _GUICtrlListView_GetItemCount ($lv_filters) For $x = 0 To _GUICtrlListView_GetItemCount ($lv_filters) - 1 $a_IPRange[$x + 1] = StringReplace(_GUICtrlListView_GetItemText ($lv_filters, $x), "|", "-") IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Ranges", "Range" & $x + 1, $a_IPRange[$x + 1]) Next Else $a_IPRange = "" EndIf Case $filter_msg = $Delete _GUICtrlListView_DeleteItemsSelected ($lv_filters) GUICtrlSetState($Delete, $GUI_DISABLE) Case $filter_msg = $Add $ip = "" For $x = 0 To 3 $ip = $ip & GUICtrlRead($filter_input[$x]) & "." Next $ip = StringTrimRight($ip, 1) GUICtrlCreateListViewItem($ip & "|" & GUICtrlRead($filter_input[4]), $lv_filters) For $x = 0 To 4 GUICtrlSetData($filter_input[$x], "") Next ;*********************************** $nCurEdit = 0 ;*********************************** Case $filter_msg = $CLOSE ExitLoop Case $filter_msg = $GUI_EVENT_PRIMARYDOWN $win_state = WinGetState($Filter_Window) If BitAND($win_state, 8) And BitAND($win_state, 2) Then If _GUICtrlListView_GetNextItem ($lv_filters) <> $LV_ERR Then GUICtrlSetState($Delete, $GUI_ENABLE) EndIf EndIf EndSelect $ip_len = True For $x = 0 To 4 If StringLen(GUICtrlRead($filter_input[$x])) == 0 Then $ip_len = False If ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_DISABLE) ExitLoop EndIf Next If $ip_len And Not ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_ENABLE) Until $filter_msg = $GUI_EVENT_CLOSE GUIDelete($Filter_Window) GUISetState(@SW_ENABLE, $MAIN_WINDOW) GUISetState(@SW_SHOW, $MAIN_WINDOW) EndFunc;==>_ConfigIpRange Func _IsPressedMod() Local $aR, $bRv, $hexKey, $i For $i = 8 To 128 $hexKey = '0x' & Hex($i, 2) $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If $aR[0] <> 0 Then Return $i Next Return 0 EndFunc;==>_IsPressedMod Func _GetIPRanges($IniFile, ByRef $IP_Range) Local $Ranges = IniReadSection($IniFile, "IP-Ranges"), $x If Not @error Then Dim $IP_Range[$Ranges[0][0] + 1] $IP_Range[0] = $Ranges[0][0] For $x = 1 To $Ranges[0][0] $IP_Range[$x] = $Ranges[$x][1] Next EndIf EndFunc;==>_GetIPRanges Func _ReduceMemory() Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) Return $ai_Return[0] EndFunc;==>_ReduceMemory Func _LockAndWait() GUISetState(@SW_LOCK) EndFunc;==>_LockAndWait Func _ResetLockWait() GUISetState(@SW_UNLOCK) GUISetCursor($Cursor_ARROW, 1) _ReduceMemory() EndFunc;==>_ResetLockWait Edited May 20, 2009 by bluechipps Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now