Leaderboard
Popular Content
Showing content with the highest reputation on 10/01/2016 in all areas
-
ChakraCore UDF - executing JavaScript in AutoIt
dariel reacted to scintilla4evr for a topic
Hello! Microsoft Edge, the new browser released with Windows 10, uses Chakra as its JavaScript engine. In January, Microsoft released ChakraCore - the open source version of the engine that can be used in other apps. So, how about using it in AutoIt? I tried 2 times to create ChakraCore UDF, and I succeeded. So here it is - the ChakraCore UDF. Features: Executing JavaScript from AutoIt (obviously) Passing data from AutoIt to JavaScript Calling AutoIt functions from JavaScript ChakraCore UDF Have fun!1 point -
Note: my first UDF. This allows sending (BSD) messages to a syslog server using UDP. It has been tested with SnmpSoft Syslog Watcher, Synology DSM 4.2 and DSM 6.0, Kiwi Syslog Server. Uses the BSD syslog protocol (https://tools.ietf.org/html/rfc3164), except for Facility and Severity levels, which incorporates the extended (newer) values as well. To the best of my knowledge, this is how most basic syslog senders do it today anyway. Target IP, Facility, Severity level, Tag, Hostname, Port can be specified. Also includes a ping feature to give an error if server doesn't respond. Feedback appreciated. #include-once Global $__SyslogSendPing ; this allows global access to the ping result (in ms) Global $__SyslogSendPacket ; this allows global access to the entire syslog packet: PRI, HEADER and MSG. ; #FUNCTION# ==================================================================================================================== ; Name ..........: SyslogSend v1.0.3 ; Modified ......: 2018.10.09 ; Changelog......: v1.0.2 fixed $MDAY formatting, leading zero would not be correctly replaced by a space ; v1.0.3 added debug console output when packet is sent. Set global variable $_D=True to show debug output. ; Description ...: Sends syslog messages to a syslog server using UDP ; Syntax ........: SyslogSend($_Message, $_Target, $_Port, $_Facility, $_Severity, $_Tag, $_HostName) ; Parameters ....: $_Message - Text message to send. https://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6.4 ; $_Target - [optional] Target IP or host (IPv4 address or hostname). Default is "127.0.0.1". ; $_Facility - [optional] Facility value (integer 0..23). Default is 1. https://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6.2.1 ; $_Severity - [optional] Severity level (integer 0..7). Default is 7. https://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6.2.1 ; $_Tag - [optional] Name of program or process (a-zA-Z0-9). https://tools.ietf.org/html/rfc3164#section-4.1.3 ; $_HostName - [optional] Originator hostname. Default is @ComputerName. https://tools.ietf.org/html/rfc3164#section-4.1.2 ; $_Port - [optional] UDP port number (integer 0..65535). Default is 514. ; $_Ping - [optional] Ping the host before sending, with value as timeout. Function will exit and return an ; error message if host did not respond. Default is 0 (no ping). ; Return values .: 0 = Success ; Non-zero = error text message ; Author ........: Irios ; Remarks .......: Uses UDP only, and sticks to the BSD syslog protocol (https://tools.ietf.org/html/rfc3164), except for Facility ; and Severity levels, which incorporates the extended (newer) values as well. To the best of my knowledge, this ; is how most basic syslog senders do it today anyway. The syslog protocol does not provide acknowledgement of message ; delivery, the ping feature is for convenience only. Most syslog servers will use the first word in the MSG field as ; TAG if you do not specify a tag yourself. This is by design, and not a bug. ; Example .......: SyslogSend("A test message", "192.168.0.1", 514, 3, 5, "SyslogSend", "fooServer", 1000) ; This would send the text string "<29> Oct 1 00:36:23 fooServer SyslogSend: A test message" to host 192.168.0.1:514 (including a ping, 1000ms timeout). ; ; =============================================================================================================================== Func SyslogSend($_Message, $_Target = "127.0.0.1", $_Facility = 1, $_Severity = 7, $_Tag = "", $_HostName = @ComputerName, $_Port = 514, $_Ping = 0) Local $_UDPStartup = False If (StringStripWS($_Message, 8) = "") Then Return "Error. Nothing to send (no message content)." If ($_Target = "") Or (Int($_Port) < 0) Or (Int($_Port) > 65535) Or (Int($_Facility) < 0) Or (Int($_Facility) > 23) Or (Int($_Severity) < 0) Or (Int($_Severity) > 7) Then Return "Argument(s) error." ; quick check to make sure most of the parameters have valid values ; Strip accidental spaces from target IP, HOSTNAME, and TAG. Adding a colon and space to the TAG field (https://tools.ietf.org/html/rfc3164#section-4.1.3) $_Target = StringStripWS($_Target, 8) $_HostName = StringStripWS($_HostName, 8) If ($_Tag <> "") Then $_Tag = StringStripWS($_Tag, 8) & ": " ; Ping the target host, and return an error if not responding If (Int($_Ping) <> 0) Then $__SyslogSendPing = Ping($_Target, $_Ping) Switch @error Case 1 $__SyslogSendPing = "" Return "Ping error. Host is offline." Case 2 $__SyslogSendPing = "" Return "Ping error. Host is unreachable." Case 3 $__SyslogSendPing = "" Return "Ping error. Bad destination." Case 4 $__SyslogSendPing = "" Return "Ping error. Other error." EndSwitch EndIf ; Format the TIMESTAMP field. Month number converted to Mmm format (https://tools.ietf.org/html/rfc3164#section-4.1.2). Replace leading zero in day with a space. Switch @MON Case 1 $MON = "Jan" Case 2 $MON = "Feb" Case 3 $MON = "Mar" Case 4 $MON = "Apr" Case 5 $MON = "May" Case 6 $MON = "Jun" Case 7 $MON = "Jul" Case 8 $MON = "Aug" Case 9 $MON = "Sep" Case 10 $MON = "Oct" Case 11 $MON = "Nov" Case 12 $MON = "Dec" EndSwitch $MDAY = " " & @MDAY ; we add a leading space for easier processing/formatting... $MDAY = StringReplace($MDAY, " 0", " ", 1) ; ...here we make sure the MDAY variable always has the same length (incl. a trailing space). Value such as "03" is illegal, and must be formatted as " 3". Local $_TimeStampNow = $MON & $MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC ; the complete TIMESTAMP field (https://tools.ietf.org/html/rfc3339) Local $_Prival = Int(($_Facility * 8) + $_Severity) ; generating the <PRIVAL> for the PRI field. Multiply the Facility number by 8 and add the numerical value of the Severity (https://tools.ietf.org/html/rfc5424#section-6.2.1) $__SyslogSendPacket = "<" & $_Prival & "> " & $_TimeStampNow & " " & $_HostName & " " & $_Tag & $_Message ; the complete syslog packet (https://tools.ietf.org/html/rfc3164#section-4.1.3) If (Eval("_D")=True) Then ConsoleWrite('DEBUG SyslogSend(): "'& $__SyslogSendPacket & '"' & @CRLF) ; debug output, uses $_D as trigger UDPStartup() ; starting the UDP service If @error Then Return "Could not start UDP service. Error " & @error Else $_UDPStartup = True EndIf Local $_Socket = UDPOpen($_Target, $_Port) ; the socket for the UDP connection If @error Then If $_UDPStartup Then UDPShutdown() Return "Could not connect. Error " & @error EndIf UDPSend($_Socket, $__SyslogSendPacket) ; sending the packet If @error Then If $_UDPStartup Then UDPShutdown() Return "Could not send the data. Error " & @error EndIf UDPCloseSocket($_Socket) ; closing the socket If @error Then If $_UDPStartup Then UDPShutdown() Return "Could not close socket. Error " & @error EndIf If $_UDPStartup Then UDPShutdown() ; Close the UDP service. EndFunc ;==>SyslogSend Changelog: v1.0.1 added #include-once v1.0.2 fixed $MDAY formatting, leading zero would not be correctly replaced by a space v1.0.3 added $_D option for debug output, see source comment for usage SyslogSend_udf.au31 point
-
Don't use FileDelete. The flags you have chosen in FileOpen will overwrite the file. So in testing, there's no reason to delete it just yet. No error or anything for me, file opens fine also. Func ArrayWriteToFile() Local $sFileToWrite = FileOpen(@DesktopDir & "\brandnewfile.txt", 8 + 2 + 512) ConsoleWrite("Debug at line: "&@ScriptLineNumber&@CRLF&@TAB&"@error: "&@error&@TAB&","&"@extended: "&@extended&@CRLF) _FileWriteFromArray($sFileToWrite, $aColletionArray) ConsoleWrite("Debug at line: "&@ScriptLineNumber&@CRLF&@TAB&"@error: "&@error&@TAB&","&"@extended: "&@extended&@CRLF) FileClose($sFileToWrite) ConsoleWrite("Debug at line: "&@ScriptLineNumber&@CRLF&@TAB&"@error: "&@error&@TAB&","&"@extended: "&@extended&@CRLF) ShellExecute(@DesktopDir & "\brandnewfile.txt") ConsoleWrite("Debug at line: "&@ScriptLineNumber&@CRLF&@TAB&"@error: "&@error&@TAB&","&"@extended: "&@extended&@CRLF) EndFunc ;==>ArrayWriteToFile1 point
-
You can use $hLog = _GUICtrlEdit_Create($mainGui,'',8, 5, 467, 314, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE, $ES_WANTRETURN, $ES_READONLY)) as Control showing the loglines and Func _report($sMsg, $hLog = 0, $iDebug = 0) ;=============================================================================== ; Autor(s): AutoBert (www.autoit.de) ; ; modified: durch/Grund hier anfügen ;=============================================================================== If $hLog <> 0 Then _GUICtrlEdit_AppendText($hLog, $sMsg & @CRLF) If $iDebug Then ConsoleWrite($sMsg & @CRLF) ;If $G__hFileLog > 0 Then _FileWriteLog($G__hFileLog, $sMsg & @CRLF) EndFunc ;==>_report to append a line.1 point
-
bloopie, This works for me. Note comments in code... #include <File.au3> #include <Array.au3> #include <FileConstants.au3> HotKeySet("{f1}", "Terminate") Global $aColletionArray RecursiveSearchArray() ArrayWriteToFile() Func RecursiveSearchArray() Local $hTimer = TimerInit() $aColletionArray = _FileListToArrayRec(@HomeDrive & "\", "Rkill.txt;FSS.txt;FSSExport.txt||Dropbox;Atwin;Geany;Nmap;Python*;Sublime*;*cortana*", 1, 1) Local $fTimeDiff = TimerDiff($hTimer) MsgBox(0, "File Gathering Complete!", "This search took " & StringLeft(($fTimeDiff / 1000), 5) & " Seconds to complete.") If IsArray($aColletionArray) Then _ArrayDisplay($aColletionArray, "Files Collected", "", 8) EndFunc ;==>RecursiveSearchArray Func ArrayWriteToFile() Local $sFileToWrite = FileOpen(@DesktopDir & "\brandnewfile.txt", 8 + 2 + 512) If $sFileToWrite = -1 Then MsgBox(0, "ERROR", "Error: " & @error & @CRLF & " - " & " Extended: " & @extended) _FileWriteFromArray(@DesktopDir & "\brandnewfile.txt", $aColletionArray) ; <- file path instead of handle If @error Then MsgBox(0, "Error", @error & @CRLF & @extended & @CRLF) fileclose($sFileToWrite) ; <- close file ShellExecute(@DesktopDir & "\brandnewfile.txt") ; <- file path instead of handle EndFunc ;==>ArrayWriteToFile Func Terminate() Exit EndFunc ;==>Terminate kyhlomas1 point
-
Your code should be like this: #include <sqlite.au3> ; do NOT use #include <sqlite.dll.au3> _SQLite_Startup("put_here_the_full_path_to\sqlite3.dll") If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended) Local $hDB = _SQLite_Open() ; for a memory DB or _SQLite_Open("myDB.sq3") for a disk-based DB If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended) ; your actual code where you use the DB _SQLite_Close($hDB) _SQLite_Shutdown() If you have a specific use case or have any question about SQLite, just ask.1 point
-
Code rearranged a little bit: #NoTrayIcon #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;#include <GuiButton.au3> ;#include <GuiTab.au3> #include <EditConstants.au3> #include <GUIToolbar.au3> ;#include <ToolbarConstants.au3> #include <GUIImageList.au3> ;Opt("GUIOnEventMode", 1) Global $main _main() Func _main() $main = GUICreate("main", 368, 343, -1, -1, -1, -1) ;GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") ;$ToolbarGUI = GUICreate('', 350, 62, 1, 1, $WS_CHILD, 0, $main) $Toolbar = _GUICtrlToolbar_Create($main, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER) $ToolbarImageList = _GUIImageList_Create(32, 32, 5, 1) _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\mmc.exe", 0, 1) _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\cmd.exe", 0, 1) _GUICtrlToolbar_SetImageList($Toolbar, $ToolbarImageList) _GUICtrlToolbar_AddString($Toolbar, 'MMC') _GUICtrlToolbar_AddString($Toolbar, 'CMD') _GUICtrlToolbar_AddButton($Toolbar, 10000, 0, 0) _GUICtrlToolbar_AddButton($Toolbar, 10001, 1, 1) _GUICtrlToolbar_SetButtonSize($Toolbar, 62, 50) _GUICtrlToolbar_SetMetrics($Toolbar, 0, 0, 1, 0) _GUICtrlToolbar_SetIndent($Toolbar, 1) _SendMessage($Toolbar, $TB_AUTOSIZE) GUICtrlCreateLabel('', 0, 63, 372, 1, $SS_ETCHEDHORZ) GUICtrlCreateButton("button", 248, 313, 100, 20, -1, -1) $tab = GUICtrlCreateTab(4, 70, 363, 226, -1, -1) GUICtrlCreateTabItem("Page 1") GUICtrlCreateTabItem("Page 2") GUICtrlCreateTabItem("") GuiRegisterMsg( $WM_NCACTIVATE, "WM_NCACTIVATE" ) ; Prevent child windows (for Tab items) in making main GUI title bar dimmed GUISetState(@SW_SHOW, $main) $pageOneGUI = GUICreate("", 352, 198, 9, 93, $WS_POPUP, $WS_EX_MDICHILD, $main) GUISetBkColor(0xCCFFCC) GUICtrlCreateGroup("Group", 6, 3, 341, 180, -1, -1) GUICtrlCreateEdit("this is an edit control", 15, 40, 325, 67, BitOR($ES_READONLY, $WS_VSCROLL), $WS_EX_CLIENTEDGE) GUICtrlCreateInput("This is an inputbox", 15, 130, 325, 20, -1, $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW, $pageOneGUI) $pageTwoGUI = GUICreate("", 352, 198, 9, 93, $WS_POPUP, $WS_EX_MDICHILD, $main) GUISetBkColor(0xCCFFCC) $idButPage2 = GUICtrlCreateButton( "Button page 2", 10, 10, 100, 20 ) GUISetState( @SW_HIDE, $pageTwoGUI ) GUISwitch($main) While 1 Switch GUIGetMsg() Case $tab Switch GUICtrlRead( $tab ) Case 0 ; Page 1 GUISetState( @SW_HIDE, $pageTwoGUI ) GUISetState( @SW_SHOW, $pageOneGUI ) Case 1 ; Page 2 GUISetState( @SW_HIDE, $pageOneGUI ) GUISetState( @SW_SHOW, $pageTwoGUI ) EndSwitch Case $idButPage2 MsgBox( 0, "Page 2", "Button clicked", 0, $main ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd #cs While 1 Sleep(100) WEnd #ce EndFunc ;==>_main Func _exit() Exit EndFunc ;==>_exit ; Prevent child windows (for Tab items) in making main GUI title bar dimmed Func WM_NCACTIVATE( $hWnd, $iMsg, $wParam ) If $hWnd = $main Then If Not $wParam Then Return 1 EndIf EndFunc The reason for message loop mode is just that I was too lazy to create all the functions.1 point
-
I did, but that first sentence prior tries to dismiss everybody elses explanation of what they are seeing. If the OP cant even reveal which flavor of RDP is being used, then this thread will be rather circular.1 point
-
shai, After giving you a step-by-step explanation, I would have expected you to make at least an attempt at coding this yourself! However, if I must: Using GUICtrlRead: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> uninstallmode() Func uninstallmode() GUICreate("remove tool", 150, 165, 0, 0, $WS_CAPTION) $serial = GUICtrlCreateInput("", 10, 10, 130, 20, $ES_NUMBER + $ES_PASSWORD) $ok_btn = GUICtrlCreateButton("ok", 10, 35, 130, 20) $next_next = GUICtrlCreateButton("next...", 10, 85, 130, 20) $after_uninstall = GUICtrlCreateButton("clear", 10, 110, 130, 20) $cancel_btn = GUICtrlCreateButton("cancel", 10, 135, 130, 20) GUICtrlSetState($ok_btn, $GUI_DISABLE) GUISetBkColor(0xFFFFFF) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $cancel_btn GUIDelete() Exit Case $ok_btn If GUICtrlRead($serial) = "000000" Then ConsoleWrite("uninstall()" & @CRLF) Exit EndIf Case $next_next ConsoleWrite("aotuuninstall()" & @CRLF) Case $after_uninstall ConsoleWrite("afteruninstall()" & @CRLF) EndSwitch If GUICtrlRead($serial) <> "" And Not BitAnd(GUICtrlGetState($ok_Btn), $GUI_ENABLE) Then GUICtrlSetState($ok_btn, $GUI_ENABLE) WEnd EndFunc ;==>uninstallmodeUsing GUIRegisterMsg (look at the GUIRegisterMsg tutorial in the Wiki if you are unsure about what this function does ): #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Global $serial, $ok_btn uninstallmode() Func uninstallmode() GUICreate("remove tool", 150, 165, 0, 0, $WS_CAPTION) $serial = GUICtrlCreateInput("", 10, 10, 130, 20, $ES_NUMBER + $ES_PASSWORD) ConsoleWrite($serial & @CRLF) $ok_btn = GUICtrlCreateButton("ok", 10, 35, 130, 20) $next_next = GUICtrlCreateButton("next...", 10, 85, 130, 20) $after_uninstall = GUICtrlCreateButton("clear", 10, 110, 130, 20) $cancel_btn = GUICtrlCreateButton("cancel", 10, 135, 130, 20) GUICtrlSetState($ok_btn, $GUI_DISABLE) GUISetBkColor(0xFFFFFF) GUISetState() GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $cancel_btn GUIDelete() Exit Case $ok_btn If GUICtrlRead($serial) = "000000" Then ConsoleWrite("uninstall()" & @CRLF) Exit EndIf Case $next_next ConsoleWrite("aotuuninstall()" & @CRLF) Case $after_uninstall ConsoleWrite("afteruninstall()" & @CRLF) EndSwitch WEnd EndFunc ;==>uninstallmode Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) If $nNotifyCode = $EN_UPDATE And $nID = $serial Then If Not BitAND(GUICtrlGetState($ok_btn), $GUI_ENABLE) Then GUICtrlSetState($ok_btn, $GUI_ENABLE) EndIf EndFunc ;==>On_WM_COMMANDNote in both cases you need to check that the button is not already enabled before enabling it - if you do not do this you get "flashing" of the control, particularly when the mouse moves. M23 P.S. And next time, please post code that runs so I do not have to add a bunch of lines to get it to work. Edit: Typnig!1 point