Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/13/2018 in all areas

  1. benched42, Having a dyslexic day? M23
    2 points
  2. This is a simple and practical way to start and manage many processes. I use it to quickly query many remote clients for varyous informations. For processes I mean external programs that can run autonomously and that allows I/O redirection. Here the advantage is that when you start a process, you can also determine which function in your main program should receive results when the external process finishes executing. So you can have different processes and different "callback" functions. The whole works nearly autonomously and asynchronously. While spawned processes works, you can perform other tasks in the main script and leave the worry of receiving and managing the results, to the pre-established functions. As I sayd, everything is almost completely automatic and the processes do their work asynchronously and independently of the flow of the main script. To check and manage processes status, you have only to call as often as possible the _TasksCheckStatus() function that will quickly handle the running processes. AdlibRegister() could be used for this ripetitive "polling". In short: 1) setup single commandlines that will "generate" your wanted result 2) establish wich function of your main script should receive the above result 3) an optional Timeout in seconds is allowed (task from point 1 will be killed at timeout) see function header for details. The provided example of use, needs to be executed in a network environment with preferably many clients, and you have to be administrator. Populate the $aIPList[] array with ClientNames (or ip addresses), and this example script will query all the clients about some informations by running many processes asincronously. Then it will collect results from the processes as soon as "answers" are available and will populate the ListView with that data. I used a ListView so that you can see that all the cells will fill (quite quickly) in an asynchronous way. If you are not in a network with many clients, then this example is nearly useless... (sorry) Hope it can be of use... (suggestions, bug reports and emrovements are welcome) MultiTask.udf #include-once ; #include "Array.au3" ; #INDEX# ======================================================================================================================= ; Title .........: Multi Task Management (tasks spawned by the user via the _TaskRun function of this udf) ; AutoIt Version : ; Language ......: ; Description ...: Functions that assists to execute and manage user's spawned tasks. ; Author(s) .....: Chimp ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _TaskRun Run a new task and stacks its references for later use ; _TasksCheckStatus Check the status of all running tasks and call the CallBack function when a task completed ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __TaskRemove frees task's stacked references ; __NOP No OPeration function ; =============================================================================================================================== Global $aTasks[1][7] = [[0]] ; Create and initialize the task reference stack to 0 ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TaskRun ; Description ...: Runs a new task as specified in $sCommand ; Syntax ........: _TaskRun($vIndex, $sCommand[, $sParser = "__NOP"[, $vTimeout = False]]) ; Parameters ....: $vIndex - A variant value passed by the caller as a reference to this task. ; this value will be returned to the callback function along with results. ; ; $sCommand - A string value containing the full command to be executed ; ; $sParser - [optional] The name of the function to be called at the end of this task. ; Default is __NOP that is a "do nothing" function. ; P.S. ; the $aParser function will be called by the _TasksCheckStatus() function when ; this task will finish to run: ; an 1D array with 4 elements will be passed to the called function: ; element [0] the caller's index reference of this task ; element [1] the StdOut result of this task ; element [2] the StdErr result of this task ; element [3] the time spent by this task ; ; $vTimeout - [optional] A variant value. Default is False. ; if specified is the number of seconds for the Timeout. ; After this amount of seconds, if this task is still running, it is killed ; ; Return values .: the total number of stacked tasks ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _TaskRun($vIndex, $sCommand, $sParser = "__NOP", $vTimeout = False) ; ; Stack structure: ; ; +-----+ ; 0 | nr. | <-- [0][0] number of running tasks ; +-----+-----+-----+-----+-----+-----+-----+ ; 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | ; +-----+-----+-----+-----+-----+-----+-----+ ; n | * | * | * | * | * | * | * | ; | | | | | | | ; | | | | | | [n][6] setted with the TimerInit() value at the start of this task. ; | | | | | | ; | | | | | [n][5] contains the required Timeout in seconds (Default is set to False = no timeout) ; | | | | | ; | | | | [n][4] The CallBack function name that will receive the results of this task ; | | | | ; | | | [n][3] the error message returned by the StdErr stream of this task ; | | | ; | | [n][2] the result of the command returned by the StdOut stream of this task ; | | ; | [n][1] the reference of this task passed by the user (will be passed back to the caller along with results) ; | ; [n][0] the PID of this running task ; ReDim $aTasks[$aTasks[0][0] + 2][7] ; add a new element to the stack $aTasks[0][0] += 1 ; add 1 to the number of running tasks ; Run the passed command with the I/O streams redirected $aTasks[$aTasks[0][0]][0] = Run($sCommand, "", @SW_HIDE, 6) ; 6 -> $STDOUT_CHILD (0x2) + $STDERR_CHILD (0x4) ; store references of this task to the stack $aTasks[$aTasks[0][0]][1] = $vIndex $aTasks[$aTasks[0][0]][4] = $sParser $aTasks[$aTasks[0][0]][5] = $vTimeout ; can be False or the number of seconds for the timeout of this task $aTasks[$aTasks[0][0]][6] = TimerInit() ; store the TimerInit() value for this task Return $aTasks[0][0] ; return the total number of running tasks EndFunc ;==>_TaskRun ; #FUNCTION# ==================================================================================================================== ; Name ..........: _TasksCheckStatus ; Description ...: Scans the status of all active tasks and checks if some task has finished its job ; This function should be called as aften as possible ; Syntax ........: _TaskCheckStatus() ; Parameters ....: None ; Return values .: number of still running tasks; * see remarks ; Author ........: Chimp ; Modified ......: ; Remarks .......: When a task finish, it is removed from the stack and results are passed to the callback function. ; An 1D array with 4 elements will be passed to the called function: ; element [0] the caller's index reference of this task ; element [1] the StdOut result of this task ; element [2] the StdErr result of this task ; element [3] the time spent by this task (approximative time) ; is an approximate datum because it also includes the delay ; added by the main loop before calling _TasksCheckStatus() ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _TasksCheckStatus() If $aTasks[0][0] = 0 Then Return 0 ; if no tasks then return Local $bEndTask ; will be setted to True if the checked task has finished or is killed by timeout Local $iPointer = 1 ; start checking from first task in the stack Local $aResults[4] ; this Array will be loaded with the results of the task Local $sCallBack ; the name of the function to call when a task ends its job Local $aArgs[2] = ["CallArgArray", ""] ; "special" array will be loaded with parameters for the CallBack function While $iPointer <= $aTasks[0][0] $bEndTask = False $aTasks[$iPointer][2] &= StdoutRead($aTasks[$iPointer][0]) ; read and store the StdOut stream $aTasks[$iPointer][3] &= StderrRead($aTasks[$iPointer][0]) ; read and store the StdErr stream ; If @error Then ; if there is an @error is because this task has finished its job If Not ProcessExists($aTasks[$iPointer][0]) Then ; if this task has finished its job $bEndTask = True ; flag the end of the work ElseIf $aTasks[$iPointer][5] <> False Then ; if task is still running see if a Timeout check was rquired and if so if is been reached If Int(TimerDiff($aTasks[$iPointer][6]) / 1000) >= $aTasks[$iPointer][5] Then ; timeout reached or exceeded!! $aTasks[$iPointer][3] = "@error Timeout " & $aTasks[$iPointer][3] ; insert an error message at the beginning of the StdErr stream StdioClose($aTasks[$iPointer][0]) ; close I/O streams ProcessClose($aTasks[$iPointer][0]) ; kill this process $bEndTask = True ; flag the end of this task EndIf EndIf If $bEndTask Then ; if this task has finished, get its results and send to the CallBack function $aResults[0] = $aTasks[$iPointer][1] ; ............. Index (the caller reference) $aResults[1] = $aTasks[$iPointer][2] ; ............. the StdOut generated by this task $aResults[2] = $aTasks[$iPointer][3] ; ............. the StdErr generated by this task $aResults[3] = TimerDiff($aTasks[$iPointer][6]) ; .. time spent by this task $sCallBack = $aTasks[$iPointer][4] ; the name of the function to be called $aArgs[1] = $aResults ; second element of the "CallArgArray" special array contains the $aResults array ; loaded with the parameters to be send to the CallBack function. (array in array) ; (the CallBack function will receive only the 1D 4 elements array $aResults) __TaskRemove($iPointer) ; remove references of this task from the stack ; call the CallBack function and pass the results of this task. ; (CallBack function should return as soon as possible because it stops the CheckStatus for the other tasks) ; Call($sCallBack, $aArgs) ; Call CallBack function --->---+ ; | ; <--- and return here ---------------------------------+ EndIf $iPointer += 1 ; check next task WEnd Return $aTasks[0][0] EndFunc ;==>_TasksCheckStatus ; Internal use. Remove the task references from the stack Func __TaskRemove($iElement) #cs If $iElement > $aTasks[0][0] Or $iElement < 1 Then Return StdioClose($aTasks[$iElement][0]) _ArrayDelete($aTasks, $iElement) #ce ; - new -------------------------------------------------- ; remove element without the _Array* udf If $iElement > 0 And $iElement <= $aTasks[0][0] Then StdioClose($aTasks[$iElement][0]) If $aTasks[0][0] > 1 Then For $i = 0 To UBound($aTasks, 2) - 1 $aTasks[$iElement][$i] = $aTasks[$aTasks[0][0]][$i] Next EndIf Else Return ; queue is empty or the required element is out of bound EndIf $aTasks[0][0] -= 1 ReDim $aTasks[$aTasks[0][0] + 1][UBound($aTasks, 2)] Return $aTasks[0][0] ; returns the number of tasks still running EndFunc ;==>__TaskRemove ; Internal use. An empty function Func __NOP($aDummy) ; NOP (No OPeration) EndFunc ;==>__NOP Example of use ; #RequireAdmin #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include '.\MultiTask.au3' ; ; IMPORTANT following array should be populated with many real HostNames ; here are just nonsense items used as placeholders Global $aIPList[] = [@ComputerName, @IPAddress1, @ComputerName, @ComputerName, 'InexistentClient', @ComputerName] Global $hGrid ; The ListView Handle Global $ahGrid[1] ; An array to keep handles of any listview row Example() MsgBox(0, "Debug:", "Done" & @CRLF & "Hit OK to exit") Func Example() Local $Form1 = GUICreate("Clients status", 760, 400) ; ; Create the ListView $hGrid = GUICtrlCreateListView("HostName|IP|Info|Last reboot|CPU|Last logon|Current logon", 0, 0, 760, 400) _GUICtrlListView_SetColumnWidth($hGrid, 0, 140) ; HostName _GUICtrlListView_SetColumnWidth($hGrid, 1, 100) ; IP _GUICtrlListView_SetColumnWidth($hGrid, 2, 80) ; Ping info ms or Off or Unknown or Timeout) _GUICtrlListView_SetColumnWidth($hGrid, 3, 120) ; Last Reboot _GUICtrlListView_SetColumnWidth($hGrid, 4, 40) ; cpu load ; last 2 columns a mutually exclusive. If there is a user logged it's shown on the last column ; if there is not a user logged then the last user that was logged is shown on column 4 instead _GUICtrlListView_SetColumnWidth($hGrid, 5, 140) ; Last logged UserId (if nobody is logged now) _GUICtrlListView_SetColumnWidth($hGrid, 6, 140) ; Currently logged UserId _GUICtrlListView_SetExtendedListViewStyle($hGrid, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ; show grid; select whole row ; GUISetState(@SW_SHOW) ; following line is needed if you have to refill the listview ; _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hGrid)) ; empty the listview ReDim $ahGrid[UBound($aIPList)] ; this loop will run all needed tasks at once. ; The results of the tasks will be managed by the callback functions (nearly) autonomously and asynchronously For $i = 0 To UBound($aIPList) - 1 $ahGrid[$i] = _GUICtrlListView_AddItem($hGrid, "") ; create a listview row ; ; ... for each client ... ; ; spawn ping commands. result will be send to the _PingParse() function _TaskRun($i, "Ping -a -n 1 -4 " & $aIPList[$i], "_PingParse") ; spawn commands to recall LoggedOn User. Result will be send to the _LoggedOn() function _TaskRun($i, "wmic /node:" & $aIPList[$i] & " computersystem get username /value", "_LoggedOn", 5) ; 5 = timeout in 5 seconds ; spawn commands to recall Last reboot time. result will be send to the _LastReboot() function _TaskRun($i, "wmic /node:" & $aIPList[$i] & " os get lastbootuptime /value", "_LastReboot", 5) ; spawn commands to recall % of CPU load. result will be send to the _CPU_load() function _TaskRun($i, "wmic /node:" & $aIPList[$i] & " cpu get loadpercentage /value", "_CPU_load", 7) Next ; now, while all tasks are running ; we could perform other activities in the meantime ; or we can wait the end of all the tasks Do Sleep(250) ; you could perform other jobs here while waiting for the tasks to finish Until Not _TasksCheckStatus() ; <-- this function performs management of running tasks ; and should be called as often as possible EndFunc ;==>Example ; below are CallBack functions ; #FUNCTION# ==================================================================================================================== ; Name ..........: _PingParse (a callback function) ; Description ...: this function analize the output of a ping command and "extract" needed infos ; it fills columns 0 1 and 2 of the list view ($aTarget[0] is the line number of the listview to be filled) ; Syntax ........: _PingParse($aTarget[, $bDomain = True]) ; Parameters ....: $sTarget - An array with Ping results passed by the MultiTasks as soon as any ping task ends ; the passed array contains following data: ; $aTarget[0] Index for this task ; $aTarget[1] StdOut from ping (the whole output of the ping) ; $aTarget[2] StdErr from ping ; $aTarget[3] Time spent by this task to complete (is NOT the ping roundtrip time) ; $bDomain - [optional] A binary value. Default is True. (keep domain info in host name) ; ; Return values .: None. It Fills Listview columns 0, 1 and 2 ; column 0 : resolved HostName or "" ; column 1 : IP address or "" (this can contain last known IP even if now is offline) ; column 2 : roundtrip time or "Unknown" or "timeout" or "Off" ; ; Author ........: Chimp ; =============================================================================================================================== Func _PingParse($aTarget, $bDomain = True) ; $aTarget contains 4 elements: [0] Index, [1] StdOut, [2] StdErr, [3] time spent by this task Local $sOutput = $aTarget[1] ; stdout Local $0, $1, $2, $3, $aMs ; Local $iAnswer = -1, $iName = -1 Local $aResult[3] = ["", "", ""] ; [0]ms, [1]HostName, [2]IP $aMs = StringRegExp($sOutput, "([0-9]*)ms", 3) If Not @error Then ; Ping replayed $aResult[0] = $aMs[UBound($aMs) - 1] ; average ms Else ; $aResult[0] = "off" EndIf $0 = StringInStr($sOutput, "Ping") $1 = StringInStr($sOutput, "[") ; HostName decoded? If $1 Then ; HostName decoded $2 = StringInStr($sOutput, "]") $3 = StringInStr($sOutput, " ", 0, -2, $1) $aResult[1] = StringMid($sOutput, $3 + 1, $1 - $3 - 1) ; HostName $aResult[2] = StringMid($sOutput, $1 + 1, $2 - $1 - 1) ; IP Else If $0 Then ; pinging an IP address? ; $aResult[1] = "" ; no HostName Local $aFindIP = StringRegExp($sOutput, "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", 3) If Not @error Then $aResult[2] = $aFindIP[0] Else ; unknown HostName $aResult[0] = "Unknown" $aResult[1] = $aIPList[$aTarget[0]] ; retrieve HostName from the $aIPList array EndIf EndIf If $bDomain = False Then Local $aSplit = StringSplit($aResult[1], ".", 2) ; 2 = $STR_NOCOUNT $aResult[1] = $aSplit[0] ; romove .domain part from the HostName EndIf If StringLeft($aTarget[2], 14) = "@error Timeout" Then $aResult[0] = "Timeout" ; Now that we have the infos, we compile related cells in ListView ; grid row-handle data column _GUICtrlListView_SetItemText($hGrid, $ahGrid[$aTarget[0]], $aResult[1], 0) ; first column "HostName" _GUICtrlListView_SetItemText($hGrid, $ahGrid[$aTarget[0]], $aResult[2], 1) ; second column "IP address" _GUICtrlListView_SetItemText($hGrid, $ahGrid[$aTarget[0]], $aResult[0], 2) ; third column "Infos about the ping" ; ConsoleWrite("Debug: " & "-> " & $aResult[0] & @TAB & $aResult[1] & @TAB & $aResult[2] & @CRLF) EndFunc ;==>_PingParse Func _LastReboot($aParameters) ; Last reboot DateTime $aParameters[1] = StringStripWS($aParameters[1], 8) Local $equal = StringInStr($aParameters[1], "=") If $equal Then _GUICtrlListView_AddSubItem($hGrid, $ahGrid[$aParameters[0]], WMIDateStringToDate(StringMid($aParameters[1], $equal + 1)), 3) ; column 3 EndIf EndFunc ;==>_LastReboot Func _CPU_load($aParameters) ; % of CPU load $aParameters[1] = StringStripWS($aParameters[1], 8) Local $equal = StringInStr($aParameters[1], "=") If $equal Then _GUICtrlListView_AddSubItem($hGrid, $ahGrid[$aParameters[0]], StringMid($aParameters[1], $equal + 1), 4) ; column 4 EndIf EndFunc ;==>_CPU_load Func _LoggedOn($aParameters) ; User now logged $aParameters[1] = StringStripWS($aParameters[1], 8) ; if none is logged, then find the user that was last logged (also using _TaskRun) If $aParameters[1] = "" Or $aParameters[1] = "UserName=" Then ; following syntax is by @iamtheky (thanks) ; https://www.autoitscript.com/forum/topic/189845-regexp-pattern-in-findstr-dos-command/?do=findComment&comment=1363106 Local $sCmd = 'cmd /c FOR /F "usebackq skip=2 tokens=1-3" %A IN (`REG QUERY ' & '"\\' & $aIPList[$aParameters[0]] & _ '\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" /REG:64 /v LastLoggedOnUser 2^>nul`) Do @echo %C' _TaskRun($aParameters[0], $sCmd, "_LastLogged", 5) ; find last logged user and, when ready, send result to _LastLogged() Else ; if someone is logged then write username to column 6 Local $aUser = StringSplit($aParameters[1], "=", 2) ; 2 = $STR_NOCOUNT _GUICtrlListView_AddSubItem($hGrid, $ahGrid[$aParameters[0]], $aUser[UBound($aUser) - 1], 6) ; column 6 EndIf EndFunc ;==>_LoggedOn Func _LastLogged($aParameters) _GUICtrlListView_AddSubItem($hGrid, $ahGrid[$aParameters[0]], $aParameters[1], 5) ; column 5 EndFunc ;==>_LastLogged Func WMIDateStringToDate($dtmDate) ; thanks to @kylomas ; https://www.autoitscript.com/forum/topic/169252-wmi-password-age-issue/?do=findComment&comment=1236082 ; reformat date to mm/dd/yyyy hh:mm:ss and zero fill single digit values Return StringRegExpReplace(StringRegExpReplace($dtmDate, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*', '$2/$3/$1 $4:$5:$6'), '(?<!\d)(\d/)', '0$1') EndFunc ;==>WMIDateStringToDate
    1 point
  3. Hi, There have been far too many occasions recently where the Mod team have been trying to determine whether a particular thread is legal and a member has posted offering help to the OP. If the Mods are concerned about a thread, please refrain from posting within it - and certainly do not offer anything at all useful - until the all-clear has been given. After this announcement has been posted, we will regard any future instances as unfriendly acts and the poster can expect to be sanctioned - you have been warned. M23
    1 point
  4. jaberwacky

    Circle Screen Saver

    I started a screen saver years ago, but I got frustrated with it. However, it's now time for me to go through my backlog to finish my scripts. This screensaver is basic but works every pixel over time. I don't know if this is suitable for those prone to seizures with the latest edits. #include <GDIPlus.au3> #include <Math.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Const $user32_dll = DllOpen("User32.dll") Const $mouse_proc_callback = DllCallbackRegister(_mouse_proc, "long", "int;wparam;lparam;") Const $mouse_hook = _create_mouse_hook($WH_MOUSE_LL) Const $dw = @DesktopWidth Const $dh = @DesktopHeight Const $hGUI = GUICreate("Circle Screen Saver", $dw, $dh, 0, 0, $WS_POPUP) _GDIPlus_Startup() Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Example() Func Example() GUISetState(@SW_SHOWNORMAL) Local $x, $y, $color, $maximum_diameter, $step_size Do $x = Random(10, $dw - 10, 1) $y = Random(10, $dh - 10, 1) $color = _random_color() $maximum_diameter = _maximum_diameter($x, $y) _GDIPlus_GraphicsClear($hGraphic, $color) $step_size = Random(1, 4, 1) ; suggested by junkew For $i = 0 To $maximum_diameter Step $step_size _draw_circle($x, $y, $i, _random_color()) Next _GDIPlus_GraphicsClear($hGraphic, $color) For $i = $maximum_diameter To 0 Step -$step_size _draw_circle($x, $y, $i, _random_color()) Next Until GUIGetMsg() = $GUI_EVENT_CLOSE _exit() EndFunc ;==>Example Func _mouse_proc($code, $w_param, $l_param) Switch $code >= 0 Case True Switch $w_param Case $WM_MOUSEMOVE _exit() EndSwitch EndSwitch Return DllCall($user32_dll, "lresult", "CallNextHookEx", "handle", $mouse_hook, "int", $code, "wparam", $w_param, "lparam", $l_param)[0] EndFunc ;==>_mouse_proc Func _create_mouse_hook(Const $hook) ; _WinAPI_SetWindowsHookEx Local Const $aResult = DllCall($user32_dll, "handle", "SetWindowsHookEx", _ "int", $hook, _ "ptr", DllCallbackGetPtr($mouse_proc_callback), _ "handle", DllCall("kernel32.dll", "handle", "GetModuleHandleW", "wstr", 0), _ "dword", 0)[0] Return @error ? SetError(@error, @extended, 0) : $aResult EndFunc ;==>_create_mouse_hook Func _draw_circle(Const $x, Const $y, Const $diameter, Const $color) ; modified by UEZ Local Const $hPen = _GDIPlus_PenCreate($color, 3) _GDIPlus_GraphicsDrawArc($hGraphic, $x - ($diameter / 2), $y - ($diameter / 2), $diameter, $diameter, 180, 360, $hPen) _GDIPlus_PenDispose($hPen) ; add this line otherwise memory leak because pen handle will be created everytime when function is called with disposing it! EndFunc ;==>_draw_circle Func _maximum_diameter(Const $x, Const $y) Local Const $half_width = $dw / 2 Local Const $half_height = $dh / 2 Select Case $x < $half_width Select Case $y < $half_height Return _Min($x, $y) * 2 Case $y >= $half_height Return _Min($x, $dh - $y) * 2 EndSelect Case $x >= $half_width Select Case $y < $half_height Return _Min($y, $dw - $x) * 2 Case $y >= $half_height Return _Min($dw - $x, $dh - $y) * 2 EndSelect EndSelect EndFunc ;==>_maximum_diameter Func _random_color() Return "0xFF" & Hex(Random(0, 255, 1) & Random(0, 255, 1) & Random(0, 255, 1), 6) EndFunc ;==>_random_color Func _exit() DllCall($user32_dll, "bool", "UnhookWindowsHookEx", "handle", $mouse_hook) DllCallbackFree($mouse_proc_callback) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndFunc ;==>_exit
    1 point
  5. The language you want to learn depends on your ambition and (professional) goal. Learn them all is the easiest advice but depends on your knowledge, mindset. Learn to write a compiler and after that you probably understand easily all kinds of programming languages and how they can be mixed. For all languages its not the language itself but the libraries/frameworks around it you should be able to catch up. For every language it will take you a 1-3 months to be familiar with the IDE, tools, libraries around it and probably much longer before you understand full frameworks. The nice part I feel from .NET that its nicely documented by microsoft with examples for the more open oriented languages stackoverflow is your friend
    1 point
  6. ScriptJunky, Just got back onto my machine and I see the same thing - it is because the MAXIMIZE resets all the control sizes and the size of the aperture to scroll. So we need to do a bit of calculation - this seems to work: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include "GUIScrollbars_Size.au3" Global $ahLabels[100] = [0], $iCount = 10 $hGUI = GUICreate("Test", 300, 300, -1, -1, $WS_OVERLAPPEDWINDOW) GUISetState() $aRet = _GUIScrollbars_Size(0, 550, 300, 300) GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL") _GUIScrollBars_Init($hGUI) _GUIScrollBars_ShowScrollBar($hGUI, $SB_VERT, True) _GUIScrollBars_ShowScrollBar($hGUI, $SB_HORZ, False) _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT, $aRet[2]) _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $aRet[3]) $hButton = GUICtrlCreateButton("Change number of labels", 10, 10, 265, 30) _Draw_Labels(10) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_RESTORE _GUIScrollbars_Restore($hGUI, True, False) Case $GUI_EVENT_MAXIMIZE $aCtrlPos_1 = ControlGetPos($hGUI, "", $ahLabels[1]) $aCtrlPos_2 = ControlGetPos($hGUI, "", $ahLabels[2]) $aClientSize = WinGetClientSize($hGUI) $aRet = _GUIScrollbars_Size(0, ($iCount + 1) * ($aCtrlPos_2[1] - $aCtrlPos_1[1]), $aClientSize[0], $aClientSize[1]) _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT, $aRet[2]) _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $aRet[3]) Case $hButton Do $iCount = Number(InputBox("Resize scroll area", "Select number of labels to display (min 6)", "", "", 240, 130)) Until $iCount > 5 _Draw_labels($iCount) $aRet = _GUIScrollbars_Size(0, ($iCount + 1) * 50, 300, 300) _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT, $aRet[2]) _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $aRet[3]) EndSwitch WEnd Func _Draw_labels($iCount) GUISwitch($hGUI) If $iCount > $ahLabels[0] Then For $i = $ahLabels[0] + 1 To $iCount $ahLabels[$i] = GUICtrlCreateLabel($i, 10, $i * 50, 265, 40) GUICtrlSetBkColor(-1, 0xFF8080) GUICtrlSetFont(-1, 18) Next Else For $i = $iCount + 1 To $ahLabels[0] GUICtrlDelete($ahLabels[$i]) Next EndIf $ahLabels[0] = $iCount EndFunc Func _Scrollbars_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $yChar, $yPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 If $__g_aSB_WindowInfo[$x][0] = $hWnd Then $iIndex = $x $yChar = $__g_aSB_WindowInfo[$iIndex][3] ExitLoop EndIf Next If $iIndex = -1 Then Return 0 Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") Switch $nScrollCode Case $SB_TOP DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) EndSwitch DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) $yPos = $Pos EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_Scrollbars_WM_VSCROLL That works for me - over to you to break it again! M23
    1 point
  7. Thanks to you both, Bilgus and Danyfirex . I will investigate the inputs from both of you later because I'm having a toothache right now . What I can say right now is that I'm creating a wrapper for GetTokenInformation(), something similar to _Security__GetTokenInformation(), but my UDF will return the requested token information in form of an array that represents information from the requested struct, instead of just returning raw bytes that need to be interpreted later. The goal is to let the complicated works done in the UDF instead of troubling the caller.
    1 point
  8. sorry I missed the second pointer Local $pSid = DllStructGetData($tPtrSid, 1) If Not _Security__IsValidSid($pSid) Then ; Just to make sure $pSid is a pointer to a valid SID MsgBox($MB_SYSTEMMODAL, "", "The SID is invalid.") ExitLoop EndIf Local $iSidBytesLen = _Security__GetLengthSid($pSid) I believe he has pretty much what you have there danyfirex also I'm guessing (.) dot access of structs is here to stay its been there over 4 years since you asked?? Thats wonderful news! #include <SecurityConstants.au3> #include <WinAPI.au3> Example_TokInfo() Func Example_TokInfo() Local $hProcess = _WinAPI_GetCurrentProcess() If @error Then Return ; check for possible errors Local $hToken = _Security__OpenProcessToken($hProcess, $TOKEN_ALL_ACCESS) ; If token is get... If $hToken Then Local Const $sTag_SID_AND_ATTRIBUTES = "ptr psid;dword Attributes" ; Get information about the type of this token: Local $tInfo = _Security__GetTokenInformation($hToken, $TOKENUSER) Local $tsa = DllStructCreate($sTag_SID_AND_ATTRIBUTES, DllStructGetPtr($tInfo)) Local $pSid = $tsa.psid Local $IsValidSid = _Security__IsValidSid($pSid) Local $tBytes, $iSidLength If $IsValidSid Then $iSidLength = _Security__GetLengthSid($pSid) $tBytes = DllStructCreate("ALIGN 4;byte[" & $iSidLength & "]", $pSid) ConsoleWrite("Sid Hex: " & DllStructGetData($tBytes, 1) & @CRLF) ConsoleWrite("Sid: " & _Security__SidToStringSid ($pSid) & @CRLF) EndIf ; Close the token handle _WinAPI_CloseHandle($hToken) EndIf Return EndFunc ;==>Example_TokInfo I'm still not sure what having the raw struct does for you I was under the impression that you were to pass the pointer directly or convert the sid to a string first and use that form in other functions @tukangusil7 I think you will have to supply more information as far as what you want to do with this data
    1 point
  9. examples of how to paste the output of the editor?
    1 point
  10. Subz

    Filemove(Solved)

    Line 8: The array should be starting at 1 not 0 Line 11: You have a condition that says that if the folder size equals -1, why? Why not just use FileExists function Line 17: Moving the folder "C:\New folder (3)" to "C:\New Folder (3)\x\x.xlsx (where x equals $sFolderName), so basically it was just moving the first file it found into that particular folder, you never specified the filename. You can see the results of your script here: (I've changed the variables so that they're readable, but the code is the same, although of just used ConsoleWrite to show your syntax. #include <File.au3> #include <AutoItConstants.au3> #include <Array.au3> $sSourceFolder = "C:\New folder (3)" $aFileList = _FileListToArrayRec($sSourceFolder, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH) _ArrayDisplay($aFileList) For $i = 0 To UBound($aFileList) - 1 ConsoleWrite("Passthrough# := " & $i & @CRLF) $sFolderName = StringTrimRight($aFileList[$i], 5) ConsoleWrite("$sFolderName := " & $sFolderName & @CRLF) $iDirSize = DirGetSize($sSourceFolder & "\" & $sFolderName) ConsoleWrite($sFolderName & " - DirSize :=" & $iDirSize & @CRLF) If $iDirSize = -1 Then ConsoleWrite($sFolderName & " - DirSize :=" & $iDirSize & @CRLF) Else ConsoleWrite('FileMove("' & $sSourceFolder & ", " & $sSourceFolder & "\" & $sFolderName & "\" & $sFolderName & ".xlsx" & '")' & @CRLF) EndIf next
    1 point
  11. Subz

    Filemove(Solved)

    I'm still not sure what you want to happen to 2.xlsx and 4.xlsx but here is the script updated: #include <Array.au3> #include <AutoItConstants.au3> #include <File.au3> #include <WinAPIShPath.au3> Local $sFileName, $iDirSize, $sFilePath= "C:\New folder (3)" Local $aFileList = _FileListToArrayRec($sFilePath, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH) _ArrayDisplay($aFileList) For $i = 1 To $aFileList[0] $sFileName = _WinAPI_PathRemoveExtension($aFileList[$i]) If FileExists($sFilePath & "\" & $sFileName) = 0 Then MsgBox(4096, "Error", $sFilePath & "\" & $sFileName & " folder does not exist.", 5) ContinueLoop EndIf $iDirSize = DirGetSize($sFilePath& "\" & $sFileName) If $iDirSize = -1 Then MsgBox(16,$sFileName, $sFilePath & "\" & $sFileName & " is empty.", 5) Else FileMove($sFilePath & "\" & $aFileList[$i], $sFilePath & "\" & $sFileName & "\" & $aFileList[$i]) EndIf next
    1 point
  12. water

    Advanced Math UDF

    When do you start
    1 point
  13. Andreik

    Advanced Math UDF

    I tried to understand how your UDF work but I failed. There are so many warning and errors thrown to console. I saw many functions defined like this one: Func __Pascal(ByRef $aRet) Local $ret[UBound($arr)+1] Local $i For $i = 0 To UBound($arr) $v1 = ($i > 0) ? $arr[$i-1] : 1 $v2 = ($i < UBound($arr)) ? $arr[$i] : 1 $ret[$i] = $v1+$v2 Next Return $ret EndFunc whici might be fine using global variables but doesn't looks good since every function might be stand alone and code easy to debug. With your last UDF version, I tried to run Mollify example and my console cry out. This might be a very useful UDF but it should be rewrite in a better manner.
    1 point
  14. $WshShell = ObjCreate("WScript.Shell") $WshShell.SendKeys("{CAPSLOCK}") "Let AutoIt shine !"
    1 point
  15. When I make websites for my project, I generally ignore the whole "SEO" part... there would be no need to give it special attention when you are using a good and responsive website framework. In my view, we shouldn't make websites more "search engine friendly". The search engines are supposed to improve... that is what most search engines do anyway, they encourage you to focus on the content, not the SEO. In a nutshell: If you have original content, ignore SEO. If you really want your website to be on the 1st page then fill your website with long and "SEO" friendly text which annoys users
    1 point
×
×
  • Create New...