Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all 12506 articles
Browse latest View live

TS admin

$
0
0

Hi,

Has anyone got any advice for creating a script to work with the above msc or has an example script already?

 

Thnaks ina dvance for any suggestions/scripts.


Delete folders found in a text file

$
0
0

Hi there!

 

I'm trying to delete old folders that are not in use anymore - the names of those folders are in a text file.

So what I want to do is have the script read the text file and compare the names in it to the actual folder names inside, and if the folder name from the list is found on the computer - delete it.

 

I am using filereadline to read from the text file, and _FileListToArrayRec to compare with the actual folders on the computer, but I need some help with the basic code. would appreciate the help..

AutoIt         
#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <file.au3> #Include <Date.au3> #include <Array.au3> ; ***** Create local logs DirCreate (@scriptdir & "test") $dir = (@scriptdir & "test"") $log = FileOpen (@scriptdir & "test"\test.log",2) ; Function for reading - text file Eof() Func Eof()     ; Create a constant variable in Local scope of the filepath that will be read/written to.     Global Const $sFilePath = @scriptdir & "\systems.txt"     ; Open the file for reading and store the handle to a variable.     Global $hFileOpen = FileOpen($sFilePath, $FO_READ)     If $hFileOpen = -1 Then         MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")         Return False     EndIf     ; Read the contents of the file using the handle returned by FileOpen.     Global $sFileRead = FileReadLine($hFileOpen, 1)     ; Close the handle returned by FileOpen.     ;FileClose($hFileOpen)     ; Display the contents of the file.     MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & $sFileRead) EndFunc ; put the root in a variable $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2, 2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] If $sFileRead = $sRoot & "\" & $aList[$i] Then             _filewritelog ($log, "Deleting, " & $sFileRead) EndIf Next FileClose($hFileOpen)

Conditional Loop Script based on Window Title

$
0
0

Hi guy's I need help I can't get my script to loop the way I want

I have an app that has popup windows that I want to close  with my script based on the window titles and tab through

the selection to close the windows down but I don't know how to repeat and make it loop the right way

 

here is my script I would like to make the ('Activation') loop until the ('User account') window pops up the go back to the top of the script again and wait for the ('Activation') windows to popup keep doing that until I end the script.

 

Can anyone help?

 

#RequireAdmin

While 1
WinWait ('Activation')

If WinActive ('Activation') Then
  Send('{TAB}{TAB}{TAB}{SPACE}')
Sleep(60)

EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

If WinWait ('User account') Then
  Send('{TAB}{TAB}{SPACE}{SPACE}')
  Sleep(60)
  Send('{TAB}{TAB}{TAB}{TAB}{SPACE}')
 

ElseIf WinWait ('Activation') Then
Send('{TAB}{TAB}{TAB}{SPACE}')

EndIf
WEnd

GUI file menu/submenu

$
0
0
$MenuFile = GUICtrlCreateMenu("File") $MenuGenerateFiles = GUICtrlCreateMenuItem("Generate", $MenuFile) $MenuExportTemplate = GUICtrlCreateMenuItem("Export Data", $MenuGenerateFiles) GUICtrlCreateMenuItem("", $MenuGenerateFiles) ; Create a separator line $ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
 
This is the code I'm using, but it fails to nest the "Export Data" under the "Generate" menu. Can anyone let me know what I'm missing here?
 
It does create the menus, but it doesn't put export data in the place I expected.

How to find first and last word of sentence with Regular Expression

$
0
0

Hi all,

How to find first and last word in a sentence with Regular expression ?. Sentence is the code from SciTE. For example if sentence is;

"For $i = 0 to 15" 

I need to extract "For from the sentence

And the same way i need last word from a sentence

"If Apple = 15 Then" 

I need "Then" from the sentence.

 

Creating variables in a For function

$
0
0
Hey guys, i'm trying to creating 7 variables in a "For" function, to not declare one by one.
But i get errors, here is the code:
Local $i = 0 Local $bday = _DateAdd("D", -$i, _NowCalcDate()) ; For $i = 0 To 6     Local $bNewDate[$i] = 0 Next ;Options Local $aArray[7] = [$bNewDate[6], $bNewDate[5], $bNewDate[4], $bNewDate[3], $bNewDate[2], $bNewDate[1], $bNewDate[0]]

Are this code stupid or am i stupid for don't see the error hahaha

Sorry i'm noob as a Autoit programmer  >_<

Debugging not working

$
0
0

Hello all,

 

For some strange reason #AutoIt3Wrapper_run_debug_mode=Y is only working in some of my scripts... Reinstalled both Autoit and Scite4autoit3 but it's still not working yet it used to work some time ago.

 

The script that doesn't work gives me this output (after this output it continues running the script without debug):

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "G:\LSD Scripts\LSD Scripts 1\LSD Scripts 1.au3" /UserParams     +>14:41:41 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X86    Environment(Language:0413) +>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\kamps495\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\kamps495\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.12.0)  from:C:\Program Files\AutoIt3  input:G:\LSD Scripts\LSD Scripts 1\LSD Scripts 1.au3 +>14:41:41 AU3Check ended.rc:0 >Running:(3.3.12.0):C:\Program Files\AutoIt3\autoit3.exe "G:\LSD Scripts\LSD Scripts 1\LSD Scripts 1.au3"     --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop !> Starting in DebugMode.. Line: @error-@extended: Line syntax +>14:41:43 AutoIt3.exe ended.rc:0 +>14:41:43 AutoIt3Wrapper Finished. >Exit code: 0    Time: 1.807

Another script (same Scite, different tab) gives me this:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "G:\LSD Scripts\Mousemover\mousemover.au3" /UserParams     +>14:48:14 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X86    Environment(Language:0413) +>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\kamps495\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\kamps495\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.12.0)  from:C:\Program Files\AutoIt3  input:G:\LSD Scripts\Mousemover\mousemover.au3 +>14:48:15 AU3Check ended.rc:0 >Running:(3.3.12.0):C:\Program Files\AutoIt3\autoit3.exe "G:\LSD Scripts\Mousemover\mousemover.au3"     --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop !> Starting in DebugMode.. Line: @error-@extended: Line syntax 0001: 0-0: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 0002: 0-0: #AutoIt3Wrapper_run_debug_mode=Y ;y = debug aan, n = debug uit 0003: 0-0: #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 0004: 0-0: Opt("WinWaitDelay", 1000)

and gives me line-by-line debug. Both have the same directives at the top:

#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_run_debug_mode=Y ;y = debug aan, n = debug uit #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

I can't figure it out for the life of me...

 

EDIT:

 

It seems that adding #RequireAdmin ANYWHERE near the beginning of the script (before or after the #Region-part) breaks the debug. I really need #RequireAdmin (without it Internet Explorer crashes on me), but I cannot debug. When adding #RequireAdmin I can run my script, but I cannot debug it...

HowTo - _FileListToArray + multiple wildcards


IE Access Denied

$
0
0

I know there have been numerous posts about this issue and that to solve the problem I should try an open the frame being referenced in a new IE window but this is not possible and would break the script (I need access to all frames at the same time).

 

However I was wondering why my code works flawlessly on windows 7, but on windows 8 and windows 10 preview it gives the access denied.

 

To give a little insight as to what I am doing, I am scripting outlook webmail so that I can click a button to forward a mail and append a subject to the subject line.  This script is working 100% on windows 7 and like I said giving an access denied when I try to read info from a frame on windows 8 and 10.  see some example code below for where the access denied is being thrown. 

  1. $oIE = _IEAttach("Outlook Web Access")
  2.  
  3.     MsgBox(0, "NO MAIL WINDOW", "Unable to find mail window.  Please log in to webmail")
  4.     Return 0
  5.  
  6. Local $oFrames = _IEFrameGetCollection($oIE)
  7. Local $iNumFrames = @extended
  8.  
  9. For $i = 0 To ($iNumFrames - 1)
  10.     $oFrame = _IEFrameGetCollection($oIE, $i)
  11.     $sTxt = _IEPropertyGet($oFrame, "innertext") & @CRLF
  12.  
  13.     If StringTrimRight($sTxt, StringLen($sTxt) - 5) = "Inbox" Then
  14.         ExitLoop ;if we found the inbox, stop looking for it
  15.     EndIf

What settings can I change to fix the issue.  I turned off XSS and I have tried numerous other settings changes to no avail.  A few months ago this script was working fine in windows 8.  Im wondering if there was an update than changed access to IE.   Any help would be appreciated

Sending files using HTTP post: (total bytes written = 0)

$
0
0

Hi everybody,

 

I'm currently working on a script for sending files to a remote server by using the HTTP post method.

It's not my fav. way of sending files, but the remote party only supports this method.

So be it.

 

After digging through many examples over the net, I've managed to create a script that seems to do the trick.

 

There is one issue with my approach.

When I'm checking the returned @extended value from _WinHttpWriteData it always returns 0, despite a 200 OK status code from the remote site.

How come, what am I doing wrong here.

 

The script runs against a public httppost test server, so if needed you can run the script as well.

 

Thanks for your time.

AutoIt         
  1. #include <WinHttp.au3>
  2.  
  3. If FileExists(@ScriptDir & "\a_text_file.txt") Then
  4.     SendFile("a_text_file.txt")
  5.     MsgBox(64,"Error","Unknown file, nothing to do")
  6.  
  7. If FileExists(@ScriptDir & "\another_text_file.txt") Then
  8.     SendFile("another_text_file.txt")
  9.     MsgBox(64,"Error","Unknown file, nothing more to do")
  10.  
  11.  
  12. Func SendFile($sFileName)
  13.  
  14.  
  15.     Local $sFolder = @ScriptDir & "\"
  16.     Local $sFileData = FileRead($sFolder & $sFileName)
  17.     Local $iFileLen = StringLen($sFileData)
  18.  
  19.     Local $bUseProxy = 0
  20.     Local $sProxyIP = "0.0.0.0"
  21.     Local $sProxyPort = "8080"
  22.  
  23.     Local $sUserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
  24.     Local $sMethod = "POST"
  25.     Local $sHttpVersion = "HTTP/1.1"
  26.  
  27.     Local $iBytesWritten
  28.     Local $sResponseHeader
  29.     Local $sResponseData
  30.     Local $hSession
  31.     Local $hConnect
  32.     Local $hRequest
  33.  
  34.     Local $sUrlPrefix = "http://"
  35.     Local $sHostName = "posttestserver.com"
  36.     Local $sUrlSuffix = "/"
  37.     Local $sPHP_Script = "post.php"
  38.     Local $sPHP_Param = "?dump&html&dir=testing_the_script"
  39.  
  40.     Local $sUserName = ""
  41.     Local $sUserPass = ""
  42.  
  43.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  44.     ; 1) Create/Open a session handle
  45.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  46.  
  47.     ;Depending on using a proxy we use the appropriate function call
  48.     If $bUseProxy = 1 Then
  49.         $hSession = _WinHttpOpen($sUserAgent,$WINHTTP_ACCESS_TYPE_NAMED_PROXY,$sProxyIP & ":" & $sProxyPort,$WINHTTP_NO_PROXY_BYPASS,0)
  50.         If @error Then ConsoleWriteError("Step 1) _WinHttpOpen(" & $sUserAgent & "," & $WINHTTP_ACCESS_TYPE_NAMED_PROXY & "," & $sProxyIP & ":" & $sProxyPort & "," & $WINHTTP_NO_PROXY_BYPASS & ",0) raises error: " & @error & @CRLF)
  51.         ConsoleWrite("Step 1) Proxy ==> $hSession: " & $hSession & @CRLF)
  52.     Else
  53.         $hSession = _WinHttpOpen($sUserAgent, $WINHTTP_ACCESS_TYPE_NO_PROXY,$WINHTTP_NO_PROXY_NAME,$WINHTTP_NO_PROXY_BYPASS,0)
  54.         If @error Then ConsoleWriteError("Step 1) _WinHttpOpen(" & $sUserAgent & "," & $WINHTTP_ACCESS_TYPE_NO_PROXY & "," & $WINHTTP_NO_PROXY_NAME & "," & $WINHTTP_NO_PROXY_BYPASS & ",0) raises error: " & @error & @CRLF)
  55.         ConsoleWrite("Step 1) No proxy ==> $hSession: " & $hSession & @CRLF)
  56.     EndIf
  57.  
  58.  
  59.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  60.     ; 2) Create/Open connection handle
  61.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  62.  
  63.     ; Are we using HTTP or HTTPS?
  64.     If StringInStr($sUrlPrefix,"Https",0) Then  ; HTTPS
  65.         If $hSession Then $hConnect = _WinHttpConnect($hSession,$sURLPrefix & $sHostName & $sUrlSuffix,$INTERNET_DEFAULT_HTTPS_PORT)
  66.         ConsoleWrite("Step 2) Executing function _WinHttpConnect(" & $hSession & "," & $sURLPrefix & $sHostName & $sUrlSuffix & "," & $INTERNET_DEFAULT_HTTPS_PORT & ") " & @CRLF)
  67.         ConsoleWrite("Step 2) $hConnect: " & $hConnect & @CRLF)
  68.  
  69.     Else        ; HTTP
  70.         If $hSession Then $hConnect = _WinHttpConnect($hSession,$sURLPrefix & $sHostName & $sUrlSuffix,$INTERNET_DEFAULT_HTTP_PORT)
  71.         ConsoleWrite("Step 2) Executing function _WinHttpConnect(" & $hSession & "," & $sURLPrefix & $sHostName & $sUrlSuffix & "," & $INTERNET_DEFAULT_HTTP_PORT & ") " & @CRLF)
  72.         ConsoleWrite("Step 2) $hConnect: " & $hConnect & @CRLF)
  73.     EndIf
  74.  
  75.  
  76.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  77.     ; 3a) Create/Open a request handle
  78.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  79.  
  80.     ; Are we using HTTP or HTTPS?
  81.     If StringInStr($sUrlPrefix,"Https",0) Then  ; HTTPS
  82.         If $hConnect Then $hRequest = _WinHttpOpenRequest($hConnect,$sMethod, $sUrlSuffix & $sPHP_Script & $sPHP_Param, $sHttpVersion,$WINHTTP_NO_REFERER, "*/*", $WINHTTP_FLAG_SECURE)
  83.         ConsoleWrite("Step 3a) Executing funcion: _WinHttpOpenRequest(" & $hConnect & "," & $sMethod & "," & $sUrlSuffix & $sPHP_Script & $sPHP_Param & "," & $sHttpVersion & "," & $WINHTTP_NO_REFERER & ",*/*," & $WINHTTP_FLAG_SECURE & ")" & @CRLF)
  84.         ConsoleWrite("Step 3a) $hRequest: " & $hRequest & @CRLF)
  85.     Else        ; HTTP
  86.         If $hConnect Then $hRequest = _WinHttpOpenRequest($hConnect,$sMethod, $sUrlSuffix & $sPHP_Script & $sPHP_Param, $sHttpVersion,$WINHTTP_NO_REFERER, "*/*", Default)
  87.         ConsoleWrite("Step 3a) Executing funcion: _WinHttpOpenRequest(" & $hConnect & "," & $sMethod & "," & $sUrlSuffix & $sPHP_Script & $sPHP_Param & "," & $sHttpVersion & "," & $WINHTTP_NO_REFERER & ",*/*," & Default & ")" & @CRLF)
  88.         ConsoleWrite("Step 3a) $hRequest: " & $hRequest & @CRLF)
  89.     EndIf
  90.  
  91.     If $sUserName <> "" Then
  92.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  93.         ; 3b)Pass credentionals before sending a request
  94.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  95.         _WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $sUserName,$sUserPass)
  96.         If @error Then ConsoleWriteError("Step 3b) _WinHttpSetCredentials raised an error: " & @error & @CRLF)
  97.         ConsoleWrite("Step 3b) Executing funcion: _WinHttpSetCredentials(" & $hRequest & "," & $WINHTTP_AUTH_TARGET_SERVER & "," & $WINHTTP_AUTH_SCHEME_BASIC & "," & $sUserName & "," & $sUserPass & ")" & @CRLF)
  98.  
  99.  
  100.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  101.         ; 3c)Send the request
  102.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  103.         If $hRequest Then _WinHttpSendRequest($hRequest,$WINHTTP_NO_ADDITIONAL_HEADERS,$WINHTTP_NO_REQUEST_DATA,0,0)
  104.         If @error Then ConsoleWriteError("Step 3c) _WinHttpSendRequest raised an error: " & @error & @CRLF)
  105.         ConsoleWrite("Step 3c) Executing funcion: _WinHttpSendRequest(" & $hRequest & "," & $WINHTTP_NO_ADDITIONAL_HEADERS & "," & $WINHTTP_NO_REQUEST_DATA & ",0,0)" & @CRLF)
  106.         ConsoleWrite("Step 3c) $hRequest: " & $hRequest & @CRLF)
  107.  
  108.  
  109.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  110.         ; 3d) End the request
  111.         ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  112.         _WinHttpReceiveResponse($hRequest)
  113.  
  114.         $sResponseHeader = _WinHttpQueryHeaders($hRequest)
  115.         If @error Then ConsoleWriteError("Step 3d) _WinHttpQueryHeaders raised an error: " & @error & @CRLF)
  116.         ConsoleWrite("Step 3d) $sResponseHeader: " & $sResponseHeader & @CRLF)
  117.  
  118.         $iStatusCode = _WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_STATUS_CODE)
  119.         If @error Then ConsoleWriteError("Step 3d) _WinHttpQueryHeaders raised an error: " & @error & @CRLF)
  120.         ConsoleWrite("Step 3d) $iStatusCode: " & $iStatusCode & @CRLF & @CRLF)
  121.     EndIf
  122.  
  123.  
  124.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  125.     ; 4) Send the next request
  126.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  127.     _WinHttpSendRequest($hRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $sFileData, $iFileLen,Default)
  128.  
  129.     If @error Then ConsoleWriteError("Step 4) _WinHttpSendRequest raised an error: " & @error & @CRLF)
  130.     ConsoleWrite("Step 4) Executing function _WinHttpSendRequest(" & $hRequest & "," & $WINHTTP_NO_ADDITIONAL_HEADERS & "," &  $sFileData & "," & $iFileLen & ",Default)" & @CRLF)
  131.     ConsoleWrite("Step 4) $hRequest: " & $hRequest & @CRLF)
  132.  
  133.  
  134.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  135.     ; 5) Write data to server
  136.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  137.     _WinHttpWriteData($hRequest,$sFileData,0)
  138.  
  139.     ;Success - Returns 1
  140.     ;- @extended receives the number of bytes written.
  141.  
  142.     $iBytesWritten = @extended
  143.     ;Despite a successful post, @extended remains 0
  144.     ;Why??????
  145.  
  146.     ConsoleWrite("Step 5) Executing function _WinHttpWriteData(" & $hRequest & "," & $sFileData & ",0)" & @CRLF)
  147.     If @error Then
  148.         ConsoleWriteError("Step 5) _WinHttpWriteData raised an error: " & @error & @CRLF)
  149.     Else
  150.         ConsoleWrite("Step 5) File " & $sFolder & $sFileName & " succesfully send to " & $sHostName & " Total bytes written: " & $iBytesWritten & @CRLF)
  151.     EndIf
  152.  
  153.  
  154.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  155.     ; 6) End the request
  156.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  157.     _WinHttpReceiveResponse($hRequest)
  158.  
  159.  
  160.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  161.     ; 7) Show response from server
  162.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  163.     $sResponseHeader = _WinHttpQueryHeaders($hRequest)
  164.     ConsoleWrite("Step 7) $sResponseHeader: " & $sResponseHeader & @CRLF)
  165.  
  166.     $iStatusCode = _WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_STATUS_CODE)
  167.     ConsoleWrite("Step 7) $iStatusCode: " & $iStatusCode & @CRLF)
  168.     ConsoleWrite("Step 7) Remote server responded with: " & _WinHttpReadData($hRequest) & @CRLF)
  169.  
  170.  
  171.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  172.     ; 8) Close handles
  173.     ; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  174.     _winHttpCloseHandle($hRequest)
  175.     _winHttpCloseHandle($hConnect)
  176.     _winHttpCloseHandle($hSession)
  177.  

Attached Files

add code to code from Autoit recorder

$
0
0

Hi, 

 

I am trying to add in code to existing code from the autoit recorder (the autoit recorder codes works fine). I am just not sure how to incorporate my If $Model statement in properly. Should that be part of the AU3RecordSetup() or should I have a separate function like DetectLaptop() ? I added that new function below. Just trying to confirm I am going down the right path with this or if I am way off base.

AutoIt         
#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=00000409)  --- #region --- Internal functions Au3Recorder Start --- #include <Process.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Dim $Model $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $StrComputer = "localhost" Func _DetectLaptop() If $Model = "HP EliteBook 2530p" Or $Model = "HP EliteBook 2540p" Or $Model = "HP EliteBook 2560p" Or $Model = "HP EliteBook 2570p" Or $Model = "HP Compaq 6530b (FG996AW#ABA)" Or $Model = "HP ProBook 6455b" Or $Model = "HP ProBook 6465b" Or $Model = "HP ProBook 6475b" Or $Model = "HP EliteBook Folio 9470m" Or $Model = "HP ProBook 645 G1"  Or $Model = "HP EliteBook Folio 9480m" Then ; Not a laptop or system not supported, do nothing _Au3RecordSetup() EndIf EndFunc Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '') If $aResult[1] <> '00000409' Then   MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000409->' & $aResult[1] & ')') EndIf EndFunc Func _WinWaitActivate($title,$text,$timeout=0)     WinWait($title,$text,$timeout)     If Not WinActive($title,$text) Then WinActivate($title,$text)     WinWaitActive($title,$text,$timeout) EndFunc _AU3RecordSetup() #endregion --- Internal functions Au3Recorder End --- Run('C:\Program Files (x86)\Hewlett-Packard\HP Connection Manager\HPConnectionManager.exe') _WinWaitActivate("HP Connection Manager","") Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}") _WinWaitActivate("Preferences","") Send("{TAB}{TAB}{DOWN}{TAB}{TAB}{SPACE}{TAB}{SPACE}{TAB}{SPACE}{TAB}{SPACE}{TAB}{ENTER}") ;Send("{TAB}{TAB}{DOWN}{TAB}{TAB}{SPACE}{TAB}{SPACE}{TAB}{SPACE}{TAB}{SPACE}{TAB}{SPACE}{TAB}{ENTER}") _WinWaitActivate("HP Connection Manager","") Send("{ALTDOWN}{F4}{ALTUP}{TAB}{ENTER}") #endregion --- Au3Recorder generated code End --- sleep (10000) _Win32_ComputerSystem() ;Get Model Func _Win32_ComputerSystem()     ;Get General PC Info     $objWMIService = ObjGet("winmgmts:\\" & $StrComputer & "\root\CIMV2")     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)     If IsObj($colItems) Then         For $objItem In $colItems             ;$DOMAIN = $objItem.Domain             $Manufacturer = $objItem.Manufacturer             $Model = $objItem.Model             ;$MachineName = $objItem.Name             ;$NumberOfProcessors = $objItem.NumberOfProcessors             ;$PartOfDomain = $objItem.PartOfDomain             ;$MEM = Round($objItem.TotalPhysicalMemory / 1024 / 1024, 0)         Next     EndIf EndFunc   ;==>_Win32_ComputerSystem _SelfDelete() Func _SelfDelete($iDelay = 0)     Local $sCmdFile     FileDelete(@TempDir & "\scratch.bat")     $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _             & ':loop' & @CRLF _             & 'del "' & @ScriptFullPath & '"' & @CRLF _             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _             & 'del ' & @TempDir & '\scratch.bat'     FileWrite(@TempDir & "\scratch.bat", $sCmdFile)     Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFunc

Hotkey gets stuck

$
0
0

Hi, i have a problem with the Hotkeyset function, when i use it the CTRL get stuck.

not just in the window i use the script but also in every other window get to after that.

 

Below you find my script and i hope you guys can point me in the right direction.

HotKeySet("^q", "INSERT") ; While 1     Sleep(100) WEnd Func INSERT()     Send("Mark | " & @MDAY & "-" & @MON & "-" & @YEAR & "  |  " & @HOUR & ":" & @MIN & " | ") EndFunc

Double click for Listview

$
0
0

I'm trying to adapt this:

GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK") Local $fDblClk = False Local $iDoubleClickTime = 200 ; _WinAPI_GetDoubleClickTime() ; 500 by default Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)     Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)     $fDblClk = True     ConsoleWrite("!Double click on: [" & $iX & "," & $iY & "]" & @CRLF)     Return $GUI_RUNDEFMSG EndFunc

To work on my List view. I already have a button called $Edit_Btn and I want to make it so when I doubleclick in the list view, it triggers the Edit_Btn case.

 

The code above seems to print out where I clicked on the console, but only when I click on the GUI background and not on the list view. Is there a easier way to make it so when I double click in a list view, it triggers the edit button?

TABs and funktions is getting ignored

$
0
0

Hi all,

 

I have a Problem with my script and I am new to AutoIt. What I want:

 

1. go to excel

2. copy a cell

3. go to my program

4. TAB 26 times to an specific field

5. paste the cell

6. go to Excel and to the next cell

7. start again

 

/Code in the End/

 

So it is all working, but sometimes my Script or PC or whatever is jumping only 25 times. Sometimes it doesn´t jump at all.

It is not all the time. Sometimes after 10 loots the jumps are wrong, sometimes after 160 , sometime everything goes well. So I have no idea how to figer it out. And what can couse this.

Something with Thread/Memory management or other Prozesses or just someting wrong in the script that couse it to crush sometimes.

 

I can not cominiicate with my program, so i can´t ask for field IDs or something like that.

Also mouse is not recomended.

 

For wrong jumps and errors  I am using Pixel CheckSums.

1. left, right, over and under the filed I want to paste someting in.

 

Maybe this is breaking the code in the rumetime ?

 

So here is my Script:

AutoIt         
  1. Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "Umstellung Union", "Umstellung - UNION"
  2.  
  3. If $iAnswer = 7 Then
  4.     MsgBox($MB_SYSTEMMODAL, "Bye bye", "OK.  Bye!")
  5.     Exit
  6.  
  7. Func jumpToUnion() ;My jump funktion
  8.     AutoItSetOption("SendKeyDelay", 50)
  9.     Send("{TAB 26}")
  10.     sleepTime100()
  11.  
  12. Func sleepTime100()
  13.     Sleep(100)
  14.  
  15. Func sleepTime20()
  16.     Sleep(20)
  17.  
  18. ;Funktions for the Pixel Check Sums
  19.  
  20. Func checkPixelUpDown()
  21.  
  22. If $iCheckSumOben <> PixelChecksum(50, 200, 1230, 410) Then
  23.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Im oberen Fensterbereich ")
  24.         Exit
  25.        
  26. If $iCheckSumUnten <> PixelChecksum(50, 485, 1230, 780) Then
  27.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Im unteren Fensterbereich")
  28.         Exit
  29. EndIf      
  30.  
  31. Func checkPixelUnion()
  32.  
  33. If $iCheckSumUnionL <> PixelChecksum(50, 420, 620, 490) Then
  34.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Links vom Unionsfeld")
  35.         Exit
  36. EndIf      
  37. If $iCheckSumUnionR <> PixelChecksum(930, 420, 1230, 490) Then
  38.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Rechts vom Unionsfeld")
  39.         Exit
  40. EndIf      
  41.  
  42. Func checkPixelNextPage()
  43. If $iCheckSumNextPage <> PixelChecksum(50, 215, 100, 360) Then
  44.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Auf zweiter Seite gesprungen")
  45.         Exit
  46.  
  47. ;Checkt für ungültiges Kammando
  48. Func checkPixelWrongAction()
  49. If $iCheckSumWrongAction <> PixelChecksum(150, 930, 270, 960) Then
  50.         MsgBox($MB_SYSTEMMODAL, "", "Ungültige Änderung! Ungültige Eingaben, SICLID bleibt hängen --> Fehler")
  51.         Exit
  52.  
  53.  
  54. Local $sAnswer = InputBox ( "Anzahl der Haendler", "Anzahl der HändlerNummern") ; getting the loops
  55.  
  56. For $i = 1 To $sAnswer
  57.  
  58. ;Go to Excel
  59. WinActivate("Microsoft Excel - TestExcelSource.xlsx")
  60. sleepTime20()
  61.  
  62. ;Copy active cell
  63. Send("^c")
  64. sleepTime20()
  65.  
  66. ;Go to my Program
  67. WinActivate("MyProgram]") ;TEST
  68. sleepTime20()
  69.  
  70. ;Safe the checksums
  71. Local $iCheckSumOben  = PixelChecksum(50, 200, 1230, 410)
  72. Local $iCheckSumUnten = PixelChecksum(50, 485, 1230, 780)
  73.  
  74. Local $iCheckSumWrongAction = PixelChecksum(150, 930, 270, 960)
  75.  
  76. Local $iCheckSumUnionL = PixelChecksum(50, 420, 620, 490)
  77. Local $iCheckSumUnionR = PixelChecksum(930, 420, 1230, 490)
  78.  
  79. ;my jump funktion
  80. jumpToUnion() ;HERE SOMETHING GOES WRONG DONT KNOW WHAT
  81.  
  82. ;Paste the cell
  83. Send("^v")
  84. sleepTime100()
  85.  
  86. ;new checksum for trying to jump out of the current page
  87. Local $iCheckSumNextPage = PixelChecksum(50, 215, 100, 360)
  88.  
  89.  
  90. ;use my check funktions
  91. checkPixelUpDown()
  92.  
  93. checkPixelWrongAction()
  94.  
  95. checkPixelUnion()
  96.  
  97. Send("{ENTER}")
  98. sleepTime20()
  99.  
  100. checkPixelNextPage()
  101.  
  102. ;Back to excel
  103. WinActivate("Microsoft Excel - TestExcelSource.xlsx")
  104.  
  105. ;Go 1 cell down
  106. Send("{DOWN}")
  107.  
  108. Next ;start the loop again
  109.  

Thanks a lot for your time

Niksan

 

What is equivalent of "Try Catch " in AutoIt

$
0
0

Hi all,

I have some lines of code which may leads to an error some times. So i need to put that code in a "Try.. Catch" block. But i couldn't find any keywords from help file. What is the equivalent of "Try..Catch" in AutoIt ?


Global - Local - Dim

$
0
0

hey guys I don't understand what Global - Local - Dim do for example here

#include <Constants.au3> ; only required for MsgBox constants
 
Global $Var_1 = "Variable 1"
Global $Var_2 = "Variable 2"
 
; Read the variables
MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "Reading", "In The Main Script" & @CRLF & @CRLF & "Variable 1 = " & $Var_1 & @CRLF & "Variable 2 = " & $Var_2)
 
; Read the variables in a function
_Function()
 
; And now read the variables again - see that $iVar_2 has changed
MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "Reading", "Back In The Main Script" & @CRLF & @CRLF & "Variable 1 = " & $Var_1 & @CRLF & "Variable 2 = " & $Var_2)
 
Func _Function()
    ; Read the variables
    MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "Reading", "In The Function" & @CRLF & @CRLF & "Variable 1 = " & $Var_1 & @CRLF & "Variable 2 = " & $Var_2)
    ; Now let us change one of the variables WITHIN the function
    $Var_2 = "Changed Variable 2"
EndFunc

 

 I have copied it and used it works fine then I removed " Global " and still it works fine same as before nothing changes so what does global do hope someone will explain what they do exactly and sorry for bad english thank you.

 

Running AutoIT EXEs with Locked screens - FAQ

$
0
0

I just finished reading the FAQ regarding:

Why doesn't my script work on a locked workstation?
 

One thing that I didn't see mentioned was to run the AUTOIT on a separate machine (either real or virtual) and RDP into the second machine.

 

One can achieve security in such a setup by locking the local machine while AUTOIT continues to run on the remote machine.

 

The remote machine doesn't seem to lock if AUTOIT is doing sends and mouse moves.

Phil

 

Switched from XP to Win7 - WinExists stops working?

$
0
0

Hello

 

I recently got a new PC at work and a script I created years ago stopped working.  Specifically the script seems unable to find an open window using:

If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then     Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf

The program I'm monitoring is running 3 reports for me.  I don't want to sit here and run and export them myself 3x a day everyday, so this script was written to handle it for me.  When I moved to the Win7 PC I just copied my script and downloaded the latest version of AutoIT.  I'm running this directly from the editor.  Here's most of the code to wait on the processing windows to close and then perform a mouse click to export the report:

AutoIt         
Sleep(500) ;give the first "Processing..." window time to pop up Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) ; Timeout after 150 seconds - since that would mean there is an issue $hWnd1 = 0 ; reset window handle for next processing window If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then     Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then     Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then     Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf Sleep(2000) MouseClick("right", 280, 174, 1, 20) Send("{DOWN 3}") Sleep(2000) Send("{RIGHT}") Sleep(2000) Send("{ENTER}") Sleep(2000) Send("{ESC}") Sleep(2000) ;all done

I'm using Opt("WinTitleMatchMode", 1).

 

I can find the window just fine when I'm not using WinExists().  Why doesn't this work after the PC upgrade and how do I fix it?

 

Thanks for any help!

 

With winhttp do you login to facebook?

$
0
0

Hello, I want to make autoit with facebook login with winhttp. Without using IE. Winhttp or is there another way?

shuffle number from 1 to 5

$
0
0

I have a script that has 5 inputs

these inputs are filled with number from 1 to 5

so:

input1 = 1

input2 = 2

input3 = 3 

input4 = 4

input3 = 5 

 

but I want it to shuffle the numbers like:

input1 = 4

input2 = 1

input3 = 5

input4 = 2

input5= 3

I dont want to use the Random function because then there is a possibilty It will chose number with the same value, I need a number from 1 to 5 to be shown but in different order

Viewing all 12506 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>