Leaderboard
Popular Content
Showing content with the highest reputation on 05/18/2017 in all areas
-
OnAutoItErrorRegister - Handle AutoIt critical errors
GoogleDude reacted to MrCreatoR for a topic
AutoIt Version: 3.3.10.2+ UDF Version: 2.0 Description: This library allows to register function for AutoIt critical errors. Usually it's syntax errors, or array-related errors. By default the UDF shows custom debug dialog, although it is not possible to perform any real debugging, but we can for example display the error message, restart application, send bug report, or just close the application. Example #1 - Displaying built-in dialog when error is received: #NoTrayIcon #AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileClose(FileOpen('%scriptdir%\OAER_RAW_SRC.tmp', 2))" #AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')" #include <GUIConstantsEx.au3> #include 'OnAutoItErrorRegister.au3' _OnAutoItErrorRegister('', '', 'My App Error', False, False) GUICreate('OnAutoItErrorRegister Example', 350, 200) GUICtrlCreateLabel('This script is just an example.' & @CRLF & @CRLF & 'It will produce a syntax error in', 25, 40, 300, 50) GUICtrlCreateLabel('5', 185, 50, 50, 40) GUICtrlSetColor(-1, 0xF20000) GUICtrlSetFont(-1, 30, 800, 0, 'Tahoma') GUICtrlCreateLabel('seconds.', 220, 67, 300, 50) GUICtrlCreateLabel('The result shown as a CUSTOM error message, you can change it!', 25, 120, 350, 20) $iUnRegister_Bttn = GUICtrlCreateButton('UnRegister AutoItError handler', 25, 140, 200, 22) GUICtrlCreateLabel('Copyright jennico, G.Sandler (MrCreatoR) © 2008 - 2015', 25, 170, 350, 80) GUICtrlSetColor(-1, 0x808080) GUICtrlSetFont(-1, 8.5, 800, 6) GUISetState() Dim $iTimer For $i = 3 To 1 Step -1 GUICtrlSetData(4, $i) $iTimer = TimerInit() While TimerDiff($iTimer) < 1000 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iUnRegister_Bttn _OnAutoItErrorUnRegister() EndSwitch WEnd Next ;We deliberately make a syntax mistake and call the error! If Random(1, 5, 1) = 3 Then MsgBox(0, '', ) Else _NotExistingFunc() EndIf Example #2 - Call user defined function when receiving error (script restart): #NoTrayIcon #AutoIt3Wrapper_Run_AU3Check=n ;!!! This must be used to ensure that raw source file is generated before compilation (because $bSetErrLine is True) #AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip #AutoIt3Wrapper_Run_After=%autoitdir%\AutoIt3.exe /AutoIt3ExecuteLine "FileDelete('%scriptdir%\OAER_RAW_SRC.tmp')" #pragma compile(Stripper, False) #include 'OnAutoItErrorRegister.au3' _OnAutoItErrorRegister('_MyErrorHandler', '', '', False, True) ;We deliberately make an array bounding error and call the error! Dim $aArr[1] MsgBox(0, '', $aArr[1]) Func _MyErrorHandler($sScriptPath, $iScriptLine, $sErrDesc, $vParams, $hBitmap) ;Restart the application Local $sMessage = StringFormat('SCRIPT FILE:\n%s\n\nSCRIPT ERROR LINE:\n%s\n\nERROR DESCRIPTION:\n%s', $sScriptPath, $iScriptLine, $sErrDesc) If StringInStr($CmdLineRaw, '/ErrorStdOut') Then If FileExists(@WindowsDir & "\Media\chord.wav") Then SoundPlay(@WindowsDir & "\Media\chord.wav") Else DllCall('user32.dll', 'int', 'MessageBeep', 'int', 0x00000010) EndIf EndIf If MsgBox(BitOR($MB_SYSTEMMODAL, $MB_YESNO), 'Crash recieved!', 'Restart application?' & @CRLF & @CRLF & $sMessage) <> 6 Then Return EndIf Local $sRunLine = @AutoItExe & ' "' & @ScriptFullPath & '"' If @Compiled Then $sRunLine = @ScriptFullPath EndIf Run($sRunLine, @ScriptDir) EndFunc Download: OnAutoItErrorRegister.zip (Counter: ) Screenshot: ChangeLog: Initial idea by jennico: Author(s): G.Sandler (MrCreatoR), jennico Notes: The UDF can not handle crashes that triggered by memory leaks, such as DllCall crashes, "Recursion level has been exceeded..." (when using hook method ($bUseStdOut = False)).When using StdOut method ($bUseStdOut = True), CUI not supported, and additional process executed to allow monitor for errors.After using _OnAutoItErrorUnRegister when $bUseStdOut = True, standard AutoIt error message will not be displayed on following syntax error.To use the "Send bug report" feature, there is need to fill related parameters (variables) under the «User Variables» section in UDF file (check the comments of these variables), or just build your own user function.[If $bSetErrLine is True...] Script must be executed before compilation (after any change in it), or use '#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip' in your main script. Do NOT use Au3Stripper when compiling the main script if you want correct error line detection for compiled script. To get correct code line for compiled script, the script is transformed to raw source (merging includes) and FileInstall'ed when it's needed (on error), therefore, the script is available in temp dir for few moments (when error is triggered), although it's crypted, but developer should ensure that his script is more protected. [If $bSetErrLine is False...] Use supplied GetErrLineCode.au3 to get proper error line code by line number from error that was triggered in compiled script.1 point -
You can try: $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True").ItemIndex(0) $hol = $colItems.Description1 point
-
Deleting Cell Value when condition is met
czardas reacted to JLogan3o13 for a topic
Or just wait until someone does it all for you1 point -
@Fredricz Try this version ; #FUNCTION# ======================================================================================================================================== ; Name .................: StringSplit2D() ; Description ..........: Splits a string into columns instead of rows as it is done by SplitString(), like a csv file to a 2d array ;-) ; Syntax ...............: StringSplit2D($sString[, $sDelimiter = ";"[, $bStripWS = True[, $sQuotationMark = '"'[, $sDummy = "¦"[, $iWidthLen = 256]]]]]) ; Parameters ...........: $sString - A string value. ; $sDelimiter - [optional] A string value. Default is ";". ; $bStripWS - [optional] A binary value. Default is True. ; $sQuotationMark - [optional] A string value. Default is '"'. ; $sDummy - [optional] A string value. Default is "¦". ; $iWidthLen - [optional] An integer value. Default is 256. ; Return values .......: Success - 2d array ; Error 1 - $sStringis not set ; Error 2 - $delimter is not set ; Error 3 - error splitting string ; Error 4 - array width exceeded ; ; Version .............: v0.97 build 2015-03-03 beta ; Author ..............: UEZ ; Modified ............: ; Comment .............: former StringSplitW ; Remarks .............: RegEx taken from http://stackoverflow.com/questions/4476812/regular-expressions-how-to-replace-a-character-within-quotes ; Related .............: StringSplit, StringReplace, StringRegExpReplace, StringLen, StringStripCR ; =================================================================================================================================================== Func StringSplit2D($sString, $sDelimiter = ";", $bStripWS = False, $sQuotationMark = '"', $sDummy = "¦", $iWidthLen = 256) If $sString = "" Then Return SetError(1, 0, 0) If $sDelimiter = "" Then Return SetError(2, 0, 0) Local $aSplit = StringSplit(StringStripCR($sString), @LF) If @error Then Return SetError(3, 0, 0) Local $chk, $iWidth, $i, $j, $k, $iLen, $iMax = 1, $iSum = 0 Local $aPos[1], $l = 0 Local $aVertical[$aSplit[0]][$iWidthLen], $iDelimiterLen = StringLen($sDelimiter) - 1, $sLine For $k = 1 To $aSplit[0] $iLen = StringLen($aSplit[$k]) If $iLen > 1 Then Switch $bStripWS Case True $sLine = StringRegExpReplace($aSplit[$k], '(?m)\' & $sDelimiter & '(?=[^' & $sQuotationMark & ']*' & $sQuotationMark & '(?:[^' & $sQuotationMark & '\r\n]*' & $sQuotationMark & '[^' & $sQuotationMark & ']*' & $sQuotationMark & ')*[^' & $sQuotationMark & '\r\n]*$)', $sDummy) Case Else ; ,(?=[^"]*"(?:[^"\r\n]*"[^"]*")*[^"\r\n]*$) $sLine = StringRegExpReplace(StringStripWS($aSplit[$k], 4), '(?m)\' & $sDelimiter & '(?=[^' & $sQuotationMark & ']*' & $sQuotationMark & '(?:[^' & $sQuotationMark & '\r\n]*' & $sQuotationMark & '[^' & $sQuotationMark & ']*' & $sQuotationMark & ')*[^' & $sQuotationMark & '\r\n]*$)', $sDummy) EndSwitch $chk = StringReplace($sLine, $sDelimiter, $sDelimiter) $iWidth = @extended $iSum += $iWidth If $iWidth > $iWidthLen Then Return SetError(4, 0, 0) If $iWidth >= $iMax Then $iMax = $iWidth + 1 Switch $iWidth Case 0 $aVertical[$l][0] = $sLine Case Else Dim $aPos[$iWidth * 2 + 2] $j = 1 $aPos[0] = 1 For $i = 0 To $iWidth - 1 $aPos[$j] = StringInStr($sLine, $sDelimiter, 0, $i + 1) - 1 $aPos[$j + 1] = $aPos[$j] + 2 + $iDelimiterLen $j += 2 Next $aPos[UBound($aPos) - 1] = StringLen($sLine) $j = 0 For $i = 0 To UBound($aPos) - 1 Step 2 $aVertical[$l][$j] = StringReplace(StringMid(StringReplace($sLine, $sDummy, $sDelimiter), $aPos[$i], $aPos[$i + 1] - $aPos[$i] + 1), '""', "") ;~ ConsoleWrite($aVertical[$l][$j] & @CRLF) $j += 1 Next EndSwitch $l += 1 EndIf Next ReDim $aVertical[$l][$iMax] Return $aVertical EndFunc or try czardas' _CSVSplit1 point
-
try the examples first https://www.autoitscript.com/autoit3/docs/functions/StderrRead.htm https://www.autoitscript.com/autoit3/docs/functions/StdOutRead.htm and based on that make your scenario work1 point
-
Github repo can be found here.1 point
-
arp -a output .txt
antonioj84 reacted to jguinch for a topic
\d : One digit \d+ : One or more digits \h : One horizontal whitespace \h+ : One or more horizontal whitespaces \. : . (dot) \V+ : One or more characters mathing a non-vertical character [:xdigit:] : One hexadecimal digit [:xdigit:]{2} : Two hexadecimal digits () : Capturing group (what you want to retrieve in the returned array) (?:) : Non-capturing group (useful to use with quantifier) ((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+) : ((?:\d+\.){3}\d+) : (1st group) (One or more digits ,and a dot) 3 times, and one or more digits \h+ : One or more horizontal whitespaces ((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2}) : (2nd group) (Two hexadecimal digits and a dash) 5 times, and two hexadecimal digits \h+ : One or more horizontal whitespaces (\V+) : (3rd group) : One or more characters mathing a non-vertical character (used to match all characters until the end of the line) https://regex101.com/r/aPdHcf/11 point -
https://www.autoitscript.com/wiki/FAQ#Why_does_the_Ctrl_key_get_stuck_down_after_I_run_my_script.3F1 point