Jump to content

Nomad_RJ

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by Nomad_RJ

  1. I had a file being tagged as "Trojan:Win32/Tilken.B!cl" by Windows Defender on Windows 10, with "severe" risk. This was the only false positive among several of my scripts, so I decided to investigate the code... Found out this particular script had "#pragma" directives, something I don't use anymore for quite a long time. So I replaced them with "#AutoIt3Wrapper" directives, recompiled and voilá, no more warnings on Windows Defender! I have no idea the reason why, but this is definitely worth checking... PS: It seems like UPX is unchecked by default by Autoit3Wrapper PS2: Using version 3.3.14.2
  2. Dear collegues, Most of my scripts batch processes lists of files running external commads, and then do something with the result (like saving a log file). They usually only have one "GO" button to start processing, but if I want to cancel the processing I have to "kill" the app. I could test if a "cancel" button was pressed between each of the external commands, but what I´m looking for is something to cancel the process right away. To help ilustrate the problem I´m including an example script. It uses an external EXE to generate MD5 hashes of the files in a provided directory. What I want is a button to "cancel" the processing, even that the external MD5.exe program is still running. Is it possible? Anyone have an idea? Thanks in advance! Nomad_RJ #include <File.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Hash Exemple", 480, 225) $sourcelabel = GUICtrlCreateLabel("Files to MD5:", 16, 10, 169, 17) $soure_ctrl = GUICtrlCreateInput("", 16, 27, 450, 21) $logpathlabel = GUICtrlCreateLabel("Output log:", 16, 53, 80, 17) $logpath_ctrl = GUICtrlCreateInput("", 16, 70, 450, 21) $subdir = GUICtrlCreateCheckbox("Include subdirs", 365, 8, 120, 17) $StatusGroup = GUICtrlCreateGroup(" Status ", 16, 100, 448, 73) $status = GUICtrlCreateLabel("", 32, 128, 430, 42) $run = GUICtrlCreateButton("Generate", 160, 187, 150, 25) GUISetState(@SW_SHOW) FileInstall(".\tools\md5.exe", @TempDir & "\", 1) ; 1=overwrite GUICtrlSetData($logpath_ctrl, @ScriptDir&"\output.csv") GUICtrlSetState($subdir,$GUI_CHECKED) Do $nMsg = GUIGetMsg() If $nMsg = $run AND GuiCtrlRead($soure_ctrl) <> "" Then Global $FileCount = 0 Local $recursive = 0 Local $src = GuiCtrlRead($soure_ctrl) Local $log = GuiCtrlRead($logpath_ctrl) If GUICtrlRead($subdir) = $GUI_CHECKED Then $recursive = 1 _RecLog($src, $log, $recursive) GUICtrlSetData($status, $FileCount & ' files processed') EndIf Until $nMsg = $GUI_EVENT_CLOSE Func _RecLog($path, $logfile, $sub) If StringRight($path,1) = "\" Then $path = StringLeft($path, StringLen($path)-1) Local $i = 1 Local $j = 1 Local $FileList = _FileListToArray($path, "*.*", 1) ;0(Default) both files and folders, 1 files only, 2 Folders only If NOT @error Then While $i <= $FileList[0] $FileCount = $FileCount + 1 GUICtrlSetData($status, $FileCount&': '&$path&'\'&$FileList[$i]) $hash = _GetHash($path&"\"&$FileList[$i]) _SaveLog($logfile, '"' & $path&'\'&$FileList[$i] & '","' & $hash & '"' & @CRLF) $i = $i + 1 WEnd EndIf Local $FolderList = _FileListToArray($path, "*", 2) ;0(Default) both files and folders, 1 files only, 2 Folders only If (NOT @error) AND $sub Then While $j <= $FolderList[0] _RecLog($path&"\"&$FolderList[$j],$logfile, $sub) $j = $j + 1 WEnd EndIf EndFunc Func _SaveLog($path,$text) Local $file = FileOpen($path, 275) ; = 1 (write) + 8 (create folder) + 128 (utf-8) FileWrite($file, $text) FileClose($file) EndFunc Func _GetHash($fullpathfile) $command = @TempDir&'\md5.exe "' & $fullpathfile & '"' $cmd = Run(@ComSpec & ' /c ' & $command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($cmd) $md5 = StringLeft(StdoutRead($cmd), 32) Return $md5 EndFunc
  3. Good to know the bug is being tracked. Nice strategy with IsObj()! That worked for me. Thanks for your time and attention!
  4. When the script is compiled with v3.3.8.1: $oMyError.windescription = "Not an Object type" When the script is compiled with v3.3.14.2: AutoIt closes with a message window "The requested action with this object has failed" (the ErrFunc don´t even is called)
  5. Sorry for my english, and for the global variables...
  6. That depends on the usage case and volume of data. If you need to handle thousands of entries, you need that data to be shared and/or edited concurrently, you need high performance and last but not least, data need to be secured/encrypted, go for a database system. For a simple admin script like the one in the exampe you gave, I would go for the simplicity of an INI/TXT file.
  7. One simple way to do that would be using an INI file. Create a custom section, like [WEBSITES], and list your urls under numbered keys. Your sample.ini file would look like this: [WEBSITES] total=3 url1=www.google.com url2=www.yahoo.com url3=www.cnn.com url4= Then you use IniRead in your script to read each line and do what you want. If you need to change an URL you just edit the ini file, which is a plain text file, and you don´t have to touch the script. Remember to update the "total" line if you change the number of URLs on the INI file (for this simple sample). You may work on a script to manage the INI file in the future... $inifile = "F:\MySamples\sample.ini" While 1 $lines = IniRead($inifile, "WEBSITES", "total", "0") ; filename, section, key, default If $lines >= 1 Then For $i = 1 to $lines $url = IniRead($inifile, "WEBSITES", "url"&$i, "") MsgBox(-1,"sample", "URL: " & $url) ; <-- DO WHAT YOU WANT HERE Next Else ;Problem reading INI File MsgBox(-1,"ERROR", "Problem reading " & $inifile) EndIf WEnd Hope that helps.
  8. Thanks mLipok! Sure I can share a piece of the code with you. I´m using the Lotus Notes (8.5) COM to handle notes databases (NSF files), mainly mail databases, but Lotus Notes have many different types of databases, like names.nsf (personal address book), log files, applications, and much more, each one with a different structure. Thats why the COM error catching is so important to me: althought I´m working on email databases, I expect, from time to time, a different database being provided, even if I can´t process it, I just log the error and keep working. Here is a sample of my code: Global $iEventError = 0 ; To be checked to know if COM error occurs. Must be reset after handling. Global $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler $inifile = GUICtrlRead($clientpath)&"notes.ini" IniWrite($inifile,"NOTES","KeyFilename",$userid) $Session = ObjCreate("Lotus.NotesSession") ;Starts a Notes Session in background $pwd = FileReadLine($userpw, 1) $Session.Initialize($pwd) If $iEventError Then _SaveLog($LogFile, "Erro ao inicializar a sessão com o Lotus Notes ($Session.Initialize). Possível erro de senha do ID. " & @CRLF) $iEventError = 0 ; Reset after displaying a COM Error occurred Return 69 EndIf $Maildb = $Session.GETDATABASE("", $file) If $iEventError Then _SaveLog($LogFile, "Erro ao abrir o arquivo NSF ($Session.GETDATABASE). Arquivo corrompido ou com problemas na estrutura. "& @CRLF) $iEventError = 0 ; Reset after displaying a COM Error occurred Return 69 EndIf $UserName = $Session.UserName $folder = $Maildb.GetView('$All') If $iEventError Then _SaveLog($LogFile, "Erro ao abrir o arquivo NSF ($Session.GETVIEW). Arquivo corrompido ou com problemas na estrutura. "& @CRLF) $iEventError = 0 ; Reset after displaying a COM Error occurred Return 69 EndIf $doc = $folder.GetFirstDocument() ;==== HERE IS WHERE v3.3.8.1 CATCHES THE ERROR, BUT v3.3.14.2 CRASHES ==== If $iEventError Then _SaveLog($LogFile, "Erro ao abrir o arquivo NSF ($Session.GetFirstDoc). Arquivo corrompido ou com problemas na estrutura. "& @CRLF) $iEventError = 0 ; Reset after displaying a COM Error occurred Return 69 EndIf Func ErrFunc() ;COM Error intercepted $sHexNumber = Hex($oMyError.number, 8) _SaveLog($LogFile, "[COMerror;" & $sHexNumber &";"& $oMyError.windescription &"]"&@CRLF) $iEventError = 1 ; Use to check when a COM Error occurs EndFunc ;==>ErrFunc I know that "$doc = $folder.GetFirstDocument()" will not work on all structures, but I don´t want the script to crash when that happens. Thanks for your help!
  9. Dear colleagues, I´ve been using the COM extensions for a while in AutoIt v3.3.8.1 with success. My ErrFunc is exactly as the example in this page: https://www.autoitscript.com/autoit3/docs/intro/ComRef.htm , except that my script write the output to a log file instead of showing an error window. I have compiled the exact same code with the two AutoIt versions to test. On v3.3.8.1 I have the following error output from ErrFunc in a particular situation: [COMerror;00000002;Not an Object type] Compiling with v3.3.14.2 and running the same particular situation stated above, I have a crash with the message "The requested action with this object has failed". I haven´t found any script breaking change related to this problem on the help file for the newest versions since 3.3.8. Anyone have any clue about this problem? Thanks in advance! Nomad_RJ
×
×
  • Create New...