#include <Array.au3>
#include <Constants.au3>
#include <Encoding.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include <GUIListBox.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Удаление ПК", 433, 610, 283, 132)
$Button1 = GUICtrlCreateButton("Найти ПК", 29, 39, 175, 25)
$Button2 = GUICtrlCreateButton("Удалить ПК", 229, 39, 175, 25)
$List1 = GUICtrlCreateListView("Пометить на удаление|Полное имя ПК", 16, 96, 401, 500)
$Label2 = GUICtrlCreateLabel("", 14, 75, 400, 17)
_GUICtrlListView_SetColumnWidth($List1, 0, 160)
_GUICtrlListView_SetColumnWidth($List1, 1, 220)
_GUICtrlListView_SetExtendedListViewStyle($List1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES))
$Graphic1 = GUICtrlCreateGraphic(0, 576, 832, 32)
GUICtrlSetBkColor(-1, 0x646464)
GUICtrlCreateGraphic(0, 0, 832, 12)
GUICtrlSetBkColor(-1, 0x646464)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_GUICtrlListView_RegisterSortCallBack($List1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_GetPC()
Case $Button2
_CheckPCtoDell()
;~ _DellPC("")
;~ _GetPC1()
Case $List1
_GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
EndSwitch
WEnd
Func _GetPC()
$sRead=""
dim $aResult[1]
$iPID = Run(@ComSpec & ' /C dsquery computer -inactive 24 -limit 10' , '', @SW_HIDE, $STDOUT_CHILD)
If Not $iPID Then
MsgBox(16, 'Error', 'Error')
Exit
EndIf
While 1
$sRead &= StdoutRead($iPID)
If @error Then ExitLoop
Sleep(10)
ConsoleWrite($sRead)
$aRead = StringSplit ($sRead,'"',3)
WEnd
;~ ConsoleWrite($sRead)
$count=1
FOR $i=1 to UBound($aRead)-1 Step 2
$iIndex = _GUICtrlListView_AddItem($List1, "" ,0, $i)
$count=$count+1
_GUICtrlListView_AddSubItem($List1, $iIndex, _Encoding_866To1251($aRead[$i]),1, $i)
next
EndFunc
Func _CheckPCtoDell()
;~ $aPCtoDEL=GUICtrlRead($List1)
For $j=0 to _GUICtrlListView_GetItemCount($List1)-1
if (_GUICtrlListView_GetItemChecked($List1,$j)==True)Then _DellPC(_GUICtrlListView_GetItemText($List1,$j,1), $j)
Next
MsgBox(0,"","ПК выбранные удалены")
;~ _ArrayDisplay($aPCtoDEL)
EndFunc
Func _DellPC($sNamePC,$j)
;~ ConsoleWrite($sNamePC&@CRLF)
$objComputer = ObjGet("LDAP://"&$sNamePC)
$objComputer.DeleteObject(0)
EndFunc