t0nZ Posted February 28, 2018 Share Posted February 28, 2018 (edited) This time I want to share this utility I developed to speed-up the helpdesk activity in our windows domain, used every day by my collegues. Our windows machines have no simple to remember name, and when a user calls it's good to quick find a set of informations about the user, the machine, the account and so on. In our domain every user and machine has a well made description, and many fields are completed. So, based on the fantastic UDF AD.au3 for active directory, I have this script that can: search both on user name - machine description, retrieving account name, name/surname, phone number , and for the machine the machine name, the description, the operating system. You can check if an account is locked, the domain group membership of an user, the expiration date of the password, you can connect via VNC (tightvnc 64bit please), you can even call the user (but this is based on a particular setup in our environment, we have another script to send commands to the desktop IPphone). The code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icone\glaze\kcontrol.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;UMD User.Machine.Domain ; (c) NSC 2017-2018 ; V.0.3 december 2017 ; V.0.4 english translated and phone fiel added ; V.0.6 autodeploy and update ; V.0.61 support for old vnc 32bit ; V.0.65 search on machine name with radio button ; V.0.66 search on machine name added to default search, removed radio buttons ; V.0.67 radio buttons restored ; V.0.70 VNC connect with no checkbox if only 1 machine found, VNC called with vnconf file, added call functionality via DTdial key combo, user password info ; V.0.71 bugfix ; V.0.75 added ip retrieval, ping if online, reverse host lookup, added tips on every command. ; V.0.76 code cleaned ;#RequireAdmin #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> #include <File.au3> #include <AD.au3> #include <_zip.au3> #include <Inet.au3> #cs ------- notes ------------------ https://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx https://social.technet.microsoft.com/wiki/contents/articles/12056.active-directory-get-adcomputer-default-and-extended-properties.aspx #CE Global $idListview, $id2Listview, $Icercato, $search1, $search2, $List_lines_Index, $List2_lines_Index, $trovati1, $trovatiPHONE1, $trovati2, $umdver = "V.0.76" Global $gollogcount = 0, $lastlog = "sicrlf", $cachelog = "", $guititle = "UMD - Users-Machines-Domain " & $umdver & " NSC 2017-2018", $Gollogedit, $logfile = @ScriptDir & "\UMD_", $months2NOTzip = 1 Global $geleft = 590, $getop = 15, $gewidth = 400, $geheight = 550 Global $prgname = "umd.exe", $umddir = "c:\autoit\UMD\", $sourceexepath = "\\yourpath", $toping = ("your ip to ping") ; environment related: $sourceexepath is for autodeploy/autoupdate, these operations depend on pinging $toping Global $OU1 = "OU=Users,OU=IT,DC=??,DC=???,DC=local", $OU2 = "OU=Clients,OU=IT,DC=??,DC=???,DC=local" ;domain related, the first is the domain OU (organizational unit) where to search for users, the second the OU for machines Global $only1machine = 0, $lastmachinefound = "", $only1user = 0, $lastphonefound = "" Global $idchkbox1, $idchkbox2, $idchkbox3 GuiGO() Func GuiGO() Local $guiheight = 620 ; gui height GUICreate($guititle, 1000, $guiheight, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x6FA8DC) GUICtrlCreateLabel("Search on Users", 5, 1, 150, 15) CLVW() GUICtrlCreateLabel("Search on Machines", 5, 286, 150, 15) $idradio1 = GUICtrlCreateRadio("on user name / machine description", 180, 286, 200, 15) GUICtrlSetState(-1, $gui_checked) GUICtrlSetTip(-1, "search in both user name - machine description, populate both lists") $idradio2 = GUICtrlCreateRadio("only on machine name", 400, 286, 150, 15) GUICtrlSetState(-1, $gui_unchecked) GUICtrlSetTip(-1, "search only in the machine name field, populates only the list below") CLVW2() $Bcerca = GUICtrlCreateButton("Search (or enter)", 5, 570, 90, 30) GUICtrlSetTip(-1, "search the string in the yellow input box") $Block = GUICtrlCreateButton("User locked? ", 95, 570, 90, 30) GUICtrlSetTip(-1, "check if selected user account is locked, only an admin can unlock it") $Busergroups = GUICtrlCreateButton("User Groups", 185, 570, 90, 30) GUICtrlSetTip(-1, "list the domain groups for the selected user") $Buserpsw = GUICtrlCreateButton("User Password", 275, 570, 90, 30) GUICtrlSetTip(-1, "retrieve password expiration") $idchkbox2 = GUICtrlCreateCheckbox("psw extra info", 275, 600, 150, 15) GUICtrlSetFont(-1, 8, 400, 0, "consolas") GUICtrlSetState(-1, $gui_unchecked) GUICtrlSetTip(-1, "all the domain info about password") $Bcall = GUICtrlCreateButton("CALL", 495, 570, 40, 30) GUICtrlSetTip(-1, "phone CALL number") $Bvnc = GUICtrlCreateButton("VNC", 535, 570, 40, 30) GUICtrlSetFont(-1, 12, 800, 0, "consolas") GUICtrlSetTip(-1, "launch VNC, if one machine no need to check it") $idchkbox1 = GUICtrlCreateCheckbox("VNC readOnly", 495, 600, 90, 15) GUICtrlSetFont(-1, 8, 400, 0, "consolas") GUICtrlSetState(-1, $gui_unchecked) GUICtrlSetTip(-1, "launch VNC in read only mode") $Icercato = GUICtrlCreateInput("", 590, 570, 400, 30, BitOR($GUI_SS_DEFAULT_INPUT, $WS_BORDER)) GUICtrlSetBkColor(-1, 0xffff4d) GUICtrlSetFont(-1, 12, 800, 0, "consolas") GUICtrlSetColor(-1, 0x000099) GUICtrlSetTip(-1, "insert here a string to search...") $idchkbox3 = GUICtrlCreateCheckbox("ip check / nslookup", 590, 600, 150, 15) GUICtrlSetFont(-1, 8, 400, 0, "consolas") GUICtrlSetState(-1, $gui_unchecked) GUICtrlSetTip(-1, "retrieve IP, check online and performs a reverse check 'nslookup', warning can slow down operations !") GUICtrlCreateLabel("Operation LOG", 590, 1) $Gollogedit = GUICtrlCreateEdit("", $geleft, $getop, $gewidth, $geheight, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_BORDER, $WS_VSCROLL)) GUICtrlSetBkColor(-1, 0x3333ff) GUICtrlSetData(-1, "" & @CRLF) GUICtrlSetFont(-1, 9, 800, 0, "consolas") GUICtrlSetColor(-1, 0xffff4d) GUISetState(@SW_SHOW) GOLLOG("UMD " & $umdver & " STARTED") autodeploy() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GOLLOG("<<<< STOP <<<<") Exit Case $Bcerca If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") Case $Block lock() Case $Busergroups usergroups() Case $Buserpsw userpsw() Case $Bcall DTdialCALL() Case $Bvnc VNC() Case $Icercato If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") EndSwitch WEnd EndFunc ;==>GuiGO Func userpsw() _AD_Open() Local $checked_List = _GUIListViewEx_ReturnArray($List_lines_Index, 1) If Not @error Then For $i = 0 To UBound($checked_List) - 1 If $checked_List[$i] = "true" Then GOLLOG("PSW info for " & $trovati1[$i + 1]) Local $arrayuserpsw = _AD_GetPasswordInfo($trovati1[$i + 1]) If BitAND(GUICtrlRead($idchkbox2), $GUI_CHECKED) = $GUI_CHECKED Then Local $arraydesk[13] = [" ", "max psw age:", "min psw age:", "n° enforced psw:", "min lenght:", "lock duration:", "lock attempts:", "lock reset", "psw last changed:", "psw expires on:", "UTC last changed:", "UTC expires on:", "psw properties:"] For $i = 1 To UBound($arrayuserpsw) - 1 GOLLOG($arraydesk[$i] & " " & $arrayuserpsw[$i]) Next Else GOLLOG("Password expires on: " & $arrayuserpsw[9]) EndIf EndIf Next Else MsgBox(0, "nothing selected", "Empty Check Array") EndIf _AD_Close() EndFunc ;==>userpsw Func usergroups() _AD_Open() Local $checked_List = _GUIListViewEx_ReturnArray($List_lines_Index, 1) If Not @error Then For $i = 0 To UBound($checked_List) - 1 If $checked_List[$i] = "true" Then GOLLOG("Query groups of " & $trovati1[$i + 1]) Local $arrayusergroups = _AD_GetUserGroups($trovati1[$i + 1], False) _ArrayDisplay($arrayusergroups) EndIf Next Else MsgBox(0, "nothing selected", "Empty Check Array") EndIf _AD_Close() EndFunc ;==>usergroups Func VNCcall($machine) IniWrite("C:\autoit\UMD\vncconf.vnc", "connection", "host", $machine) If BitAND(GUICtrlRead($idchkbox1), $GUI_CHECKED) = $GUI_CHECKED Then IniWrite("C:\autoit\UMD\vncconf.vnc", "options", "viewonly", "1") Else IniWrite("C:\autoit\UMD\vncconf.vnc", "options", "viewonly", "0") EndIf Run("c:\program files\tightvnc\tvnviewer.exe -optionsfile=C:\autoit\UMD\vncconf.vnc -password=apollo") EndFunc ;==>VNCcall Func VNC() If $only1machine = 1 Then GOLLOG("VNC to :" & $lastmachinefound) VNCcall($lastmachinefound) Else Local $checked_List = _GUIListViewEx_ReturnArray($List2_lines_Index, 1) If Not @error Then For $i = 0 To UBound($checked_List) - 1 If $checked_List[$i] = "true" Then GOLLOG("connecting to :" & $trovati2[$i + 1]) VNCcall($trovati2[$i + 1]) EndIf Next Else MsgBox(0, "multiple machines and nothing selected", "Empty Check Array") EndIf EndIf EndFunc ;==>VNC Func CALLnow($number2call) ; Create a subGUI Local $callGUI = GUICreate("calling", 200, 40) Local $callinput = GUICtrlCreateInput($number2call, 10, 5, 180, 20) GUISetState(@SW_SHOW, $callGUI) GUICtrlSetState($callinput, $GUI_FOCUS) Sleep(500) Send("+{END}") Sleep(200) If @OSVersion = "WIN_8" Or @OSVersion = "WIN_81" Or @OSVersion = "WIN_10" Then Send("{LWINdown}<") Else Send("{LWINdown}z") EndIf Sleep(100) Send("{LWINup}") Sleep(1000) ; Delete the previous subGUI GUIDelete($callGUI) EndFunc ;==>CALLnow Func DTdialCALL() If ProcessExists("dtdial.exe") Then If $only1user = 1 Then GOLLOG("to call :" & $lastphonefound) Local $number2call = InputBox("UMD calling", "modify the number", $lastphonefound) CALLnow($number2call) Else Local $checked_List = _GUIListViewEx_ReturnArray($List_lines_Index, 1) If Not @error Then For $i = 0 To UBound($checked_List) - 1 If $checked_List[$i] = "true" Then GOLLOG("call selected :" & $trovatiPHONE1[$i + 1]) Local $number2call = InputBox("UMD calling", "modify the number", $trovatiPHONE1[$i + 1]) If $number2call = "" Then GOLLOG("nothing to call") Else CALLnow($number2call) EndIf EndIf Next Else MsgBox(0, "multiple machines and nothing selected", "Empty Check Array") EndIf EndIf Else GOLLOG("*** call function") GOLLOG("*** not available") GOLLOG("*** outside DT phone system") EndIf EndFunc ;==>DTdialCALL Func lock() _AD_Open() Local $checked_List = _GUIListViewEx_ReturnArray($List_lines_Index, 1) If Not @error Then For $i = 0 To UBound($checked_List) - 1 If $checked_List[$i] = "true" Then If _AD_IsObjectLocked($trovati1[$i + 1]) = 1 Then GOLLOG($trovati1[$i + 1]) GOLLOG("account is LOCKED !") If MsgBox(36, "Unlock ?", "Do you want to unlock account " & $trovati1[$i + 1] & " ?") = $idyes Then If _AD_UnlockObject($trovati1[$i + 1]) = 0 Then GOLLOG("error " & @error) Else GOLLOG("Unlock DONE !") EndIf Else GOLLOG("not unlocked...") EndIf Else GOLLOG($trovati1[$i + 1]) GOLLOG("account is UNlocked.") EndIf EndIf Next Else MsgBox(0, "nothing selected", "Empty Check Array") EndIf _AD_Close() EndFunc ;==>lock Func Multisearch($searchtype) GOLLOG("_____Load domain data_____") renewlistview() Local $cercato = GUICtrlRead($Icercato) Local $List_lines = '', $List2_lines = '', $string2search = '' $trovatiPHONE1 = 0 Dim $trovati1[1] = ["zero"] Dim $trovatiPHONE1[1] Dim $trovati2[1] = ["zero"] _AD_Open() GOLLOG("Searched for " & $cercato) If $searchtype = "username-machinedescription" Then $search1 = _AD_GetObjectsInOu($OU1, "", 2, "SamAccountName,name,ipphone,telephonenumber") If @error = 0 Then Local $conta1 = 0 Local $conta1trovati = 0 $string2search = '' While $search1[0][0] > $conta1 $conta1 += 1 If StringInStr($search1[$conta1][0], $cercato) <> 0 Then $List_lines = $search1[$conta1][0] & "|" & $search1[$conta1][1] & "|" & $search1[$conta1][2] & " " & $search1[$conta1][3] $lastphonefound = $search1[$conta1][2] & " " & $search1[$conta1][3] ; to save last machine found GUICtrlCreateListViewItem($List_lines, $idListview) _ArrayAdd($trovati1, $search1[$conta1][0]) _ArrayAdd($trovatiPHONE1, $search1[$conta1][2] & " " & $search1[$conta1][3]) $conta1trovati += 1 EndIf WEnd ; Initiate LVEx - use filling array - no count parameter - default insert mark colour (black) - drag image - sortable + not select all text + editable headers $List_lines_Index = _GUIListViewEx_Init($idListview, $List_lines, 0, 0, True, 1 + 2 + 8) GOLLOG("checked n° " & $conta1 & " users") GOLLOG("Found n° " & $conta1trovati & " users") If $conta1trovati = 1 Then $only1user = 1 Else $only1user = 0 EndIf Else GOLLOG("error in user search " & @error) EndIf $search2 = _AD_GetObjectsInOu($OU2, "", 2, "name,description,operatingSystem") ;search in machines If @error = 0 Then Local $conta2 = 0 Local $conta2trovati = 0 $string2search = '' While $search2[0][0] > $conta2 $conta2 += 1 If StringInStr($search2[$conta2][1], $cercato) <> 0 Or StringInStr($search2[$conta2][0], $cercato) <> 0 Then $List2_lines = $search2[$conta2][0] & "|" & $search2[$conta2][1] & "|" & $search2[$conta2][2] $lastmachinefound = $search2[$conta2][0] ; to save last machine found GUICtrlCreateListViewItem($List2_lines, $id2Listview) If BitAND(GUICtrlRead($idchkbox3), $GUI_CHECKED) = $GUI_CHECKED Then ; V.0.75 IPrelated($search2[$conta2][0]) EndIf _ArrayAdd($trovati2, $search2[$conta2][0]) $conta2trovati += 1 EndIf WEnd ; Initiate LVEx - use filling array - no count parameter - default insert mark colour (black) - drag image - sortable + not select all text + editable headers $List2_lines_Index = _GUIListViewEx_Init($id2Listview, $List2_lines, 0, 0, True, 1 + 2 + 8) GOLLOG("Checked n° " & $conta2 & " machines") GOLLOG("Found n° " & $conta2trovati & " machines") If $conta2trovati = 1 Then $only1machine = 1 Else $only1machine = 0 EndIf Else GOLLOG("error in machines search " & @error) EndIf EndIf ; second searchtype----------------------------------------------------------------------_-_--------------------------- If $searchtype = "machinename-username" Then $search2 = _AD_GetObjectsInOu($OU2, "", 2, "name,description,operatingSystem") ;search in machines If @error = 0 Then Local $conta2 = 0 Local $conta2trovati = 0 $string2search = '' While $search2[0][0] > $conta2 $conta2 += 1 If StringInStr($search2[$conta2][0], $cercato) <> 0 Then $List2_lines = $search2[$conta2][0] & "|" & $search2[$conta2][1] & "|" & $search2[$conta2][2] GUICtrlCreateListViewItem($List2_lines, $id2Listview) If BitAND(GUICtrlRead($idchkbox3), $GUI_CHECKED) = $GUI_CHECKED Then ; V.0.75 IPrelated($search2[$conta2][0]) EndIf _ArrayAdd($trovati2, $search2[$conta2][0]) $conta2trovati += 1 EndIf WEnd ; Initiate LVEx - use filling array - no count parameter - default insert mark colour (black) - drag image - sortable + not select all text + editable headers $List2_lines_Index = _GUIListViewEx_Init($id2Listview, $List2_lines, 0, 0, True, 1 + 2 + 8) GOLLOG("Checked n° " & $conta2 & " machines") GOLLOG("Found n° " & $conta2trovati & " machines") Else GOLLOG("error in machines search " & @error) EndIf EndIf _AD_Close() EndFunc ;==>Multisearch Func IPrelated($pinghost) Local $sIPAddress = "" Local $shostname = "" Local $pcping = Ping($pinghost) If $pcping = 0 Then Select Case @error = 1 Local $errorping = "host is offline" Case @error = 2 Local $errorping = "host is unreachable" Case @error = 3 Local $errorping = "bad destination" Case @error = 4 Local $errorping = "not found for other errors" EndSelect GOLLOG($pinghost & " " & $errorping) Else GOLLOG($pinghost & " ping in " & $pcping & " ms") ; Start the TCP service. TCPStartup() $sIPAddress = TCPNameToIP($pinghost) $shostname = _TCPIpToName($sIPAddress, 0) TCPShutdown() ; Close the TCP service. GOLLOG("IP address is: " & $sIPAddress) GOLLOG("reverse lookup:" & $shostname) EndIf EndFunc ;==>IPrelated Func autodeploy() ; pensato per la prima installazione e update Local $TipDT = Ping($toping) Local $ntest = 1 While $TipDT = 0 And $ntest < 3 Sleep(200) $TipDT = Ping($toping) $ntest += 1 WEnd If $TipDT = 0 Then GOLLOG("unable to check updates") Else If Not FileExists($umddir) Then GOLLOG("Procedo con Autodeploy") If DirCreate($umddir) Then GOLLOG("-> creata cartella " & $umddir) Else GOLLOG("-> problema ! non creata cartella " & $umddir) EndIf GOLLOG("posiziono eseguibile in " & $umddir) FileCopy(@ScriptDir & "\umd.exe", $umddir & "umd.exe", 1) If Not FileExists(@DesktopDir & "\umd.lnk") Then GOLLOG("desktop link creation...") FileCreateShortcut($umddir & "\" & $prgname, @DesktopDir & "\umd.lnk") EndIf GOLLOG("posiziono VNConf in " & $umddir) FileCopy($sourceexepath & "\vncconf.vnc", $umddir & "\" & "vncconf.vnc", 1) GOLLOG("AutoDeploy completato") ; ora devo spegnere e riavviare quello in \cpa_da Local $sCmdFile ; phoenix modificata NON è quella standard di autoupdate FileDelete(@TempDir & "\phoenix.bat") $sCmdFile = 'ping 127.0.0.1 -n 2 > NUL' & @CRLF _ & ':loop' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'start c:\autoit\umd\umd.exe' & @CRLF _ & 'del %0' FileWrite(@TempDir & "\phoenix.bat", $sCmdFile) GOLLOG("program is closing, see ya in deployed version...") Sleep(1000) Run(@TempDir & "\phoenix.bat", @TempDir, @SW_HIDE) Exit ; exit and real update EndIf Local $currtime = FileGetTime(@ScriptDir & "\" & $prgname, $FT_MODIFIED, 1) Local $newtime = FileGetTime($sourceexepath & "\" & $prgname, $FT_MODIFIED, 1) If $newtime > $currtime Then GOLLOG("update available!") If Not FileExists(@DesktopDir & "\umd.lnk") Then GOLLOG("desktop link creation...") FileCreateShortcut($umddir & "\" & $prgname, @DesktopDir & "\umd.lnk") EndIf Local $sCmdFile GOLLOG("posiziono VNConf in " & $umddir) FileCopy($sourceexepath & "\vncconf.vnc", $umddir & "\" & "vncconf.vnc", 1) FileDelete(@TempDir & "\phoenix.bat") $sCmdFile = 'ping 127.0.0.1 -n 2 > NUL' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'copy "' & $sourceexepath & '"\"' & $prgname & '" "' & @ScriptFullPath & @CRLF _ & 'start ' & @ScriptFullPath & @CRLF _ & 'del %0' FileWrite(@TempDir & "\phoenix.bat", $sCmdFile) GOLLOG("program is closing, see ya in next version..") Sleep(1000) Run(@TempDir & "\phoenix.bat", @TempDir, @SW_HIDE) Exit ; exit and real update Else GOLLOG("UMD already updated") EndIf EndIf EndFunc ;==>autodeploy Func renewlistview() ; cancella e ricrea GUICtrlDelete($idListview) GUICtrlDelete($id2Listview) CLVW() CLVW2() EndFunc ;==>renewlistview Func CLVW() ;crea listview utenti $idListview = GUICtrlCreateListView("SamAccountName|Name|phone", 5, 15, 570, 265, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_SetColumnWidth($idListview, 0, 175) _GUICtrlListView_SetColumnWidth($idListview, 1, 175) _GUICtrlListView_SetColumnWidth($idListview, 2, 150) GUICtrlSetFont(-1, 9, 800, 0, "consolas") EndFunc ;==>CLVW Func CLVW2() ;crea listview macchine $id2Listview = GUICtrlCreateListView("Name|Description|Operating System", 5, 300, 570, 265, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($id2Listview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_SetColumnWidth($id2Listview, 0, 120) _GUICtrlListView_SetColumnWidth($id2Listview, 1, 180) _GUICtrlListView_SetColumnWidth($id2Listview, 2, 230) GUICtrlSetFont(-1, 9, 800, 0, "consolas") EndFunc ;==>CLVW2 Func GOLLOG($logtext) ; Gollog V.2.3 gestione CRLF si o no ; gestione a capo automatico oltre i xx caratteri; gestione pulitura ogni totmila char Perla pearl ; basta aggiungere |nocrlf50 a fine stringa, dove 50 sono gli xx caratteri, conta la prima riga dove si supera quel limite. ; to declare $gollogcount = 0,$lastlog="sicrlf",$cachelog="",$guititle = "nomegui",$Gollogedit,$logfile = @ScriptDir & "\GOLLOG_LOG_", $months2NOTzip = 3 ; e anche le misure dell'edit: $geleft = 32, $getop = 32, $gewidth = 553, $geheight = 377 ; #include <File.au3> #include <GuiEdit.au3> #include <_zip.au3> ; to insert FUNCs: GOLLOG CLEANEDIT GOLzipZIP $gollogcount += StringLen($logtext) Local $logfiletimerange = @YEAR & @MON Local $linelimit = StringRight($logtext, 2) If StringRight($logtext, 9) = "|nocrlf" & $linelimit Then $logtext = StringTrimRight($logtext, 9) Local $acapo = "no" Else Local $acapo = "si" $gollogcount += 4 If $gollogcount > 13000 Then Sleep(3000) cleanedit() $gollogcount = 0 EndIf EndIf If $acapo = "no" And (StringLen($cachelog) <= $linelimit) Then ;pearl perla non a capo se If $lastlog = "nocrlf" Then If WinExists($guititle) Then ; per non scrivere in gui se questa non esiste _GUICtrlEdit_AppendText($Gollogedit, $logtext) EndIf Else If WinExists($guititle) Then ; per non scrivere in gui se questa non esiste _GUICtrlEdit_AppendText($Gollogedit, @MDAY & "/" & @MON & "_" & @HOUR & ":" & @MIN & " " & $logtext) EndIf EndIf $cachelog = $cachelog & $logtext $lastlog = "nocrlf" Else If $lastlog = "nocrlf" Then If WinExists($guititle) Then ; per non scrivere in gui se questa non esiste _GUICtrlEdit_AppendText($Gollogedit, $logtext & @CRLF) EndIf $cachelog = $cachelog & $logtext _FileWriteLog($logfile & $logfiletimerange & ".txt", $cachelog) $cachelog = "" Else If WinExists($guititle) Then ; per non scrivere in gui se questa non esiste _GUICtrlEdit_AppendText($Gollogedit, @MDAY & "/" & @MON & "_" & @HOUR & ":" & @MIN & " " & $logtext & @CRLF) EndIf _FileWriteLog($logfile & $logfiletimerange & ".txt", $logtext) EndIf $lastlog = "sicrlf" EndIf EndFunc ;==>GOLLOG Func cleanedit() ; cleaning of edit every n° lines (in program put if $nlines > xlines then this function) GUICtrlDelete($Gollogedit) $Gollogedit = GUICtrlCreateEdit("", $geleft, $getop, $gewidth, $geheight) ;, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_BORDER)) GUICtrlSetData(-1, "" & @CRLF) GUICtrlSetFont(-1, 9, 800, 0, "consolas") GUICtrlSetColor(-1, 0xffff4d) GUICtrlSetBkColor(-1, 0x3333ff) GUICtrlSetCursor(-1, 3) EndFunc ;==>cleanedit Func GOLzipLOG($months2NOTzip) ; zipping old log leaving unzipped only n months GOLLOG("Starting old logs zipping..") ; path extraction zone Local $logfiletimerange = @YEAR & @MON Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $arraylogpath = _PathSplit($logfile & $logfiletimerange & ".txt", $sDrive, $sDir, $sFileName, $sExtension) Local $logpath = $arraylogpath[1] & $arraylogpath[2] Local $hSearch = FileFindFirstFile($logfile & "*.txt") ; searching for logs Local $logconta = 0 While 1 ; single file processing cycle Local $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop Local $stringtime = StringTrimRight(StringRight($sFileName, 10), 4) ;obtaining year-month like 201609 If $logfiletimerange - $stringtime > $months2NOTzip Then ;zipping If Not FileExists($logfile & ".zip") Then If Not _Zip_Create($logfile & ".zip", 1) Then GOLLOG("Error " & @error & " creating " & $logfile & ".zip") Else GOLLOG("Created new log archive: " & $logfile & ".zip") EndIf Else GOLLOG("adding to archive: " & $logfile & ".zip") EndIf If Not _zip_additem($logfile & ".zip", $logpath & $sFileName) Then GOLLOG("Error " & @error & " zipping: " & $logpath & $sFileName) Else GOLLOG("Added: " & $logpath & $sFileName) $logconta += 1 If Not FileDelete($logpath & $sFileName) Then GOLLOG("ERROR - Unable to DELETE log file " & $logpath & $sFileName) EndIf EndIf EndIf WEnd GOLLOG("Finished = " & $logconta & " log files zipped") EndFunc ;==>GOLzipLOG The minimum for make it work in your domain (no admin rights required, no writing on domain performed) is to modify these globals: Global $prgname = "umd.exe", $umddir = "c:\autoit\UMD\", $sourceexepath = "\\the .exe path for autodeploy", $toping = ("ip to ping") ; environment related: $sourceexepath is for autodeploy/autoupdate, these operations depend on pinging $toping Global $OU1 = "OU=Users,OU=IT,DC=??,DC=???,DC=local", $OU2 = "OU=Clients,OU=IT,DC=??,DC=???,DC=local" ;domain related, the first is the domain OU (organizational unit) where to search for users, the second the OU for machines. You have to recompile modifying at minimum $toping with a NON pingable IP (to disable auto deploy - update) and certainly the domain OU for your users and machines. The vncconf.vnc is to be modified with the standard (I hope for you..) VNC password in your company, OR you can remove the line and VNC will request the psw every time. After, Just copy the executable and the other file (vncconf.vnc) in a folder in your PC and try it. The autodeploy/update feature work in this way: if the script can ping $toping value, then pick the executable from $sourceexepath, and perform "installation" (link and copying .exe, no win register involved) or updating. Let me know your experience.. vncconf.vnc UMD.au3 Edited February 28, 2018 by t0nZ Earthshine, coffeeturtle and Draygoes 3 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