Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/30/2020 in all areas

  1. Here another approach to check if a script was already started using atoms and semaphores. Atom: #include <MsgBoxConstants.au3> Global $iSingleton = Singleton() If Not $iSingleton Then Exit MsgBox($MB_TOPMOST, "Singleton Test", "Process is already running!") EndIf MsgBox($MB_TOPMOST, "Singleton Test", "Singleton atom initialized: " & $iSingleton) Singleton_Delete($iSingleton) ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton ; Description ...: Checks if the script has been started already. ; Syntax ........: Singleton([$sOccurrenceName = @ScriptFullPath]) ; Parameters ....: $sOccurrenceName - [optional] a string value. Default is @ScriptFullPath. ; Return values .: If the function succeeds, the return value is the newly created atom or 0 else error is set and false is returned. ; Author ........: UEZ ; Modified ......: ; Remarks .......: If Singleton finds the atom it will return 0 and the atom token will be set to extended macro. It can be used to get the atom string using _WinAPI_AtomGlobalGetName. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalfindatomw ; https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globaladdatomw ; Example .......: No ; =============================================================================================================================== Func Singleton($sOccurrenceName = @ScriptFullPath) Local $iFind = _WinAPI_AtomGlobalFind($sOccurrenceName) If @error Then Return SetError(1, 0, False) If $iFind Then Return SetExtended($iFind, 0) Local $iAtom = _WinAPI_AtomGlobalAdd($sOccurrenceName) If @error Then Return SetError(2, 0, False) Return $iAtom EndFunc ;==>Singleton ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton_Delete ; Description ...: Deletes the atom generated by the first started script. ; Syntax ........: Singleton_Delete($iAtom) ; Parameters ....: $iAtom - an integer value which was generated by Singleton ; Return values .: True if successful else false. ; Author ........: UEZ ; Modified ......: ; Remarks .......: Don't forget to call Singleton_Delete before first started script ends. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globaldeleteatom ; Example .......: No ; =============================================================================================================================== Func Singleton_Delete($iAtom) _WinAPI_AtomGlobalDelete($iAtom) If @error Then Return SetError(1, 0, False) Return True EndFunc ;==>Singleton_Delete ;internal functions Func _WinAPI_AtomGlobalFind($sAtomString) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalFindAtomW", "wstr", $sAtomString) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] EndFunc ;==>_WinAPI_AtomGlobalFind Func _WinAPI_AtomGlobalAdd($sAtomString) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalAddAtomW", "wstr", $sAtomString) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] EndFunc ;==>_WinAPI_AtomGlobalAdd Func _WinAPI_AtomGlobalDelete($nAtom) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalDeleteAtom", "short", $nAtom) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] = 0 EndFunc ;==>_WinAPI_AtomGlobalDelete Func _WinAPI_AtomGlobalGetName($nAtom, $iBufferSize = 512) Local $tBufferAtom = DllStructCreate("wchar name[" & $iBufferSize & "]") Local $aReturn = DllCall("kernel32.dll", "uint", "GlobalGetAtomNameW", "short", $nAtom, "struct*", $tBufferAtom, "int", $iBufferSize) If @error Or Not $aReturn[0] Then Return SetError(1, 0, -1) Return $tBufferAtom.name EndFunc ;==>_WinAPI_AtomGlobalGetName Semaphore: #include <MsgBoxConstants.au3> #include <WinAPIError.au3> Global $iSingleton = Singleton("&]8h/x87</htFV4-K*&.b.w~") If Not $iSingleton Then Exit MsgBox($MB_TOPMOST, "Singleton Test", "Process is already running!") EndIf MsgBox($MB_TOPMOST, "Singleton Test", "Singleton Semaphore initialized: " & $iSingleton) ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton ; Description ...: Checks if the script has been started already. ; Syntax ........: Singleton($sOccurrenceName) ; Parameters ....: $sOccurrenceName - a string value which will be used to create the semaphore handle. ; Return values .: True if Singleton started the first time. False if script was already started ; Author ........: UEZ ; Modified ......: ; Remarks .......: The system closes the handle automatically when the process terminates. The semaphore object is destroyed when its last handle has been closed. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsemaphorea ; Example .......: No ; =============================================================================================================================== Func Singleton($sOccurrenceName) If StringLen($sOccurrenceName) > 260 Then $sOccurrenceName = StringLeft($sOccurrenceName, 260) Local $aReturn = DllCall("kernel32.dll", "handle", "CreateSemaphoreA", "ptr", Null, "long", 0, "long", 1, "str", $sOccurrenceName) If @error Or Not $aReturn[0] Then Return SetError(1, 0, -1) Return SetExtended($aReturn[0], $aReturn[0] And _WinAPI_GetLastErrorMessage() = "The operation completed successfully.") EndFunc ;==>Singleton Just start the script twice to see if it works. The disadvantage of using atoms is that atoms have a memory that means when your app is crashing or you forgot to delete the atom then the atom does still have the $sOccurrenceName saved and thus Singleton will not work if you use the same same value for $sOccurrenceName. With semaphore you don't have this issue. Thanks to jj2007 and SARG.
    4 points
  2. Purpose (from Microsoft's website) The HTTP Server API enables applications to communicate over HTTP without using Microsoft Internet Information Server (IIS). Applications can register to receive HTTP requests for particular URLs, receive HTTP requests, and send HTTP responses. The HTTP Server API includes SSL support so that applications can exchange data over secure HTTP connections without IIS. Description There have been several times in the past that I wanted to either retrieve information from one of my PCs or execute commands on one of my PCs, whether it was from across the world or sitting on my couch. Since AutoIt is one of my favorite tools for automating just about anything on my PC, I looked for ways to make to make it happen. Setting up a full blown IIS server seemed like overkill so I looked for lighter weight solutions. I thought about creating my own AutoIt UDP or TCP servers but that just wasn't robust enough, Then I found Microsoft's HTTP Server API and it looked very promising. After doing a little research into the APIs, I found that it was flexible & robust enough to handle just about any of the tasks that I required now and in the future. So a while back I decided to wrap the API functionality that I needed into an AutoIt UDF file to allow me to easily create the functionality I needed at the time. It has come in very handy over the years. Of course it wasn't all wrapped up with a nice little bow like it is now. That only happened when I decided to share it with anyone else who could use it or learn from it. The example file that I included is a very granular example of the steps required to get a lightweight HTTP Server up and listening for GET requests. The UDF is a wrapper for the Microsoft APIs. That means to do anything over and above what I show in the example, one would probably have to have at least a general knowledge of APIs or the ability to figure out which APIs/functions to use, what structures and data is needed to be passed to them, and in what order. However, the UDF gives a very solid foundation on which to build upon. Of course, if anyone has questions about the UDF or how to implement any particular functionality, I would probably help to the extent that I could or point you in the right direction so that you can figure out how to implement your own solution. Being that this is basically an AutoIt wrapper for the Microsoft API functions, there's no need to create AutoIt-specific documentation. All of the UDF functions, structures, constants, and enumerations are named after their Microsoft API counterparts. Therefore, you can refer to Microsoft's extensive documentation of their HTTP Server API. The APIs included in the UDF are the only ones that I have needed in the past to do what I needed to do. If you would like any additional APIs to be added to the UDF file, please suggestion them. Related Links Microsoft HTTP Server API - Start Page Microsoft HTTP Server API - API v2 Reference Microsoft HTTP Server API - Programming Model >>> See screen shots and DOWNLOAD in the Files section <<<
    3 points
  3. Version v1.4.0

    827 downloads

    Purpose (from Microsoft's website) The HTTP Server API enables applications to communicate over HTTP without using Microsoft Internet Information Server (IIS). Applications can register to receive HTTP requests for particular URLs, receive HTTP requests, and send HTTP responses. The HTTP Server API includes SSL support so that applications can exchange data over secure HTTP connections without IIS. Description There have been several times in the past that I wanted to either retrieve information from one of my PCs or execute commands on one of my PCs, whether it was from across the world or sitting on my couch. Since AutoIt is one of my favorite tools for automating just about anything on my PC, I looked for ways to make to make it happen. Setting up a full blown IIS server seemed like overkill so I looked for lighter weight solutions. I thought about creating my own AutoIt UDP or TCP server but that just wasn't robust enough, Then I found Microsoft's HTTP Server API and it looked very promising. After doing a little research into the APIs, I found that it was flexible & robust enough to handle just about any of the tasks that I required now and in the future. So a while back I decided to wrap the API functionality that I needed into an AutoIt UDF file to allow me to easily create the functionality I needed at the time. It has come in very handy over the years. Of course it wasn't all wrapped up with a nice little bow like it is now. That only happened when I decided to share it with anyone else who could use it or learn from it. The example file that I included is a very granular example of the steps required to get a lightweight HTTP Server up and listening for GET requests. The UDF is a wrapper for the Microsoft APIs. That means to do anything over and above what I show in the example, one would probably have to have at least a general knowledge of APIs or the ability to figure out which APIs/functions to use, what structures and data is needed to be passed to them, and in what order. However, the UDF gives a very solid foundation on which to build upon. Of course, if anyone has questions about the UDF or how to implement any particular functionality, I would probably help to the extent that I could or point you in the right direction so that you can figure out how to implement your own solution. The APIs included in the UDF are the ones that I needed in the past to do what I needed to do. If any additional APIs need to be added to the UDF file, please make those suggestions in the related forum topic. Being that this is basically an AutoIt wrapper for the Microsoft API functions, there's no need to create AutoIt-specific documentation. All of the UDF functions, structures, constants, and enumerations are named after their Microsoft API counterparts. Therefore, you can refer to Microsoft's extensive documentation of their HTTP Server API. As stated earlier, if there is one or more APIs that you find yourself needing for your particular solution, please suggest it in the related Example Scripts forum topic. Related Links Microsoft HTTP Server API - Start Page Microsoft HTTP Server API - API v2 Reference Microsoft HTTP Server API - Programming Model
    2 points
  4. Thanks! Yes. As soon as I figure out the little issue I'm having with it being able to run in a WOW64 environment, I will post detailed steps on how to enable SSL. Basically, the easiest way to do it would be to import your SSL certificate (self-signed or from a real CA) into the correct certificate store and then execute the netsh command to register that cert with the URL that you are using. https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
    2 points
  5. After having lot of issues myself with getting ImageSearch to work I decided to make topic with explanation how to proper use this script. Here is link of original topic at this topic: Credits to kangkeng for creating such useful piece of code. What is ImageSearch? It's script that find part of screen which you before defined with given image. When should I use ImageSearch? You should use it whenever it's not possible or unlikely that pixelsearch will give what you need. So how can I use ImageSearch and enjoy it's awesome benefits? First of all to avoid mostly caused problems I recompiled DLLs for both architectures which you can download at end of this post. When you pick your package you should place both ImageSearch.au3 and ImageSearch.dll inside script folder. Usage Example: First of all take picture of what you want to search for (print screen + paint + corp + save as bmp). Place that picture in script directory (I named my picture checkImage (checkImage.bmp is full name with extension). You must include ImageSearch.au3 in your script. ImageSearch.au3 consist of 2 Functions you can use: _ImageSearch and _ImageSearchArea Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify a desktop region to search Values to put in for _ImageSearch function (entire screen search) ($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0) Values to put in for _ImageSearchArea function (you declare part of screen to be searched) ($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0) Description of parameters from ImageSearch.au3 itself: ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 Example of my script using _ImageSearch ( entire screen search) #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd Example of my script using _ImageSearchArea #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEnd I would like to apologize if by writing this I offended any of member that thinks this script is too simple to even have it explained, it's just as me being new to autoIt it took me so much time getting around errors and making this script to work. Thanks for reading, if you bump on any problems using it post it here, I will try to help you fixing it and update topic for further reference. Download links: 32bit: ImageSearch 32bit.rar 64bit: ImageSearch 64 bit.rar
    1 point
  6. You can use Global $iSingleton = Singleton() Singleton_Delete(@extended) to delete the atom. But you cannot use this in you main script because how do you know if it was called the 1st time?
    1 point
  7. Yes, as you figured out, you can also do it using the API.
    1 point
  8. WOW, you always with cool stuff Can you show an example of SSL usage ?. Edit: ..ok, a next version will add HttpSetServiceConfiguration()
    1 point
  9. I was compiling to x86 and running in x64 machine. Is where I saw the issue. I think if it work compiling as x86 would probably work correctly running in a x86 OS. I'll review later. When I'm in from of computer. Saludos
    1 point
  10. I've found what I think is the issue, which are the _declspec declarations on the C++ functions. Now I just have to figure out how I'm going to resolve it in AutoIt.
    1 point
  11. I just created a 2nd version of the httpapi.au3 file, called httpapi_x86.au3 that removes all of the references to ":cdecl", which changes the calls to stdcall. When using it in a wow64 environment, it works better but as you stated, HttpSendHttpResponse has an issue. I will look at the parameters to see where there error is happening. It looks like I will need to create a slightly modified version of the UDF for x86 environments. Thanks for finding and reporting this issue. I should have it resolved in a bit.
    1 point
  12. I did a small check and seems to be calls need to be stdcall. also there is an issue HttpSendHttpResponse maybe some structure is not compatible. Saludos
    1 point
  13. Thanks Danyfirex! I wasn't aware that it didn't run in x86. I will see if I can figure out why and post back here.
    1 point
  14. As far as I know, you can't edit your posts as long as you still have the status "new member". 24 hours after registration you will get the status "member" which allows you to edit your posts (there might be also an additional minimum of 5 postings). An optional parameter does not need to be specified, not even with "" (as @Subz has already described). However, if your self-written function allows two or more optional parameters and you want to pass the second one, you can do it like this : ; use optional parameters as declared in the function header : _ExampleWithMultipleOptParams() ; set first parameter : _ExampleWithMultipleOptParams("set inidividual Param1") ; set second parameter (first parameter remains as default) : _ExampleWithMultipleOptParams(Default, "set inidividual Param2") Func _ExampleWithMultipleOptParams($sOptParam1 = "default Param1", $sOptParam2 = "default Param2") If $sOptParam1 = Default Then $sOptParam1 = "default Param1" If $sOptParam2 = Default Then $sOptParam2 = "default Param2" MsgBox(BitOR(4096, 64), "Optional Parameters :", _ "OptParam1 = " & $sOptParam1 & @CRLF & _ "OptParam2 = " & $sOptParam2 & @CRLF) EndFunc ;==>_ExampleWithMultipleOptParams
    1 point
  15. You can use both, also to open your url you could use ShellExecute, example: Func _7zip() ; Returns path and filename to 7-zip or shoots error Local $sHKLM = @OSArch = "x64" ? "HKLM64" : "HKLM" Local $sReg = RegRead($sHKLM & "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe", "Path") If @error Then $sReg = RegRead($sHKLM & "\SOFTWARE\7-Zip", "Path") ; Read registry value If @error Then ; Not found! _7zip_WEB() ; This function will write a generic message and invite user to visite https://7zip.org EndIf EndIf $sReg &= "7z.exe" ; Append executable filename $sReg = FileGetShortName($sReg) ; Get short name so you don't need quotes to executable on the command line If @error Then ; 7z.exe cannot be found or another error _7zip_WEB() ; This function will write a generic message and invite user to visite https://7zip.org EndIf Return $sReg ; Return proper path and filename EndFunc ;==>_7zip Func _7zip_WEB($sMess = "Cannot find 7zip on this computer.") ; Generic 7-zip missing message Local $iMsgBox = MsgBox(308, "Error _7zip()", $sMess & @CRLF & "Would you like to visit https://7-zip.org?") If $iMsgBox = 6 Then ShellExecute("https://7-zip.org", "", "", "", @SW_MAXIMIZE) Exit 14 ; Exit program with error code 14 EndFunc ;==>_7zip_WEB
    1 point
  16. You're calling the function with: _7zip_WEB("") Which will return "" To return the default use _7zip_WEB() Also if you want to get the path just use RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe", "Path") you don't need to query both 32/64 bit hives.
    1 point
  17. @sarge You need to add this -- _WD_Option('Port', 9515) to establish the port number in each script so that it can interact with the webdriver console. Otherwise, it uses the default of 0.
    1 point
  18. @argumentum doesn't matter what i pipe it to (and i don't intend to pipe it to base64, i actually intend to pipe it to a php-cli parent), i just want to know how to write binary data to stdout ( for @Melba23 it's not really a PHP thing, most languages can do it (for example in C++ std::cout << std::string("\x00",1); ) but i figured it out: ; binary safe ConsoleWrite() ( AutoIt's builtin ConsoleWrite() is not binary safe, it chokes if you try to write a null byte to stdout) Func ConsoleWriteBinarySafe( Const ByRef $str) Local $bytesWritten=0; Local $stdoutHandle=_WinAPI_GetStdHandle(1); Local $tBuffer = DllStructCreate("byte[" & StringLen($str) & "]"); DllStructSetData($tBuffer, 1, $str); _WinAPI_WriteFile ( $stdoutHandle, $tBuffer, StringLen($str), $bytesWritten); return $bytesWritten; EndFunc and it seems AutoIt string variables are indeed binary safe, now doing $test=""; for $i = 0 To 255 $test = $test & Chr($i); Next ConsoleWriteBinarySafe($test); does indeed write every byte from 0 to 255 to stdout
    1 point
  19. Q. - "how do you destroy...." A. -
    1 point
  20. HansHenrik, The first element of the string is Chr(0) which AutoIt interprets (along with much else) as EOF and so prints nothing. Next question? M23
    1 point
  21. Short answer: "The volunteering devs had time for it" ... after longer thinking about ........ my guess is .... CoronaVirus effect
    1 point
  22. Hi everyone, Some good news for you among all the gloom of these virus-ridden times: Nine, Subz and Danyfirex have accepted the invitation to become MVPs. Please join me in congratulating them on their new status in our community. Keep safe out there, M23
    1 point
  23. FredAI

    System restore UDF

    Hi. I needed this for one of my apps, and all I could find here was a WMI object function to create a restore point, so I decided to create this UDF and post it here. It has functions to enumerate, delete (one or all) and create restore points. Also enable or disable the system restore, and restore the system to one of the restore points. There are only two functions available through DllCall on msdn, the others are WMI. The UDF is not commented yet, I'll do it tomorrow and update. It's getting late, now. Better call it a night. Sorry for the delay. Here's the commented updated version: (28 downloads before) Note: Some functions were slightly modified. Updated 15/11/2011 (66 total downloads). The $DriveL optional parameter in the _SR_Enable and _SR_Disable functions must be in the format $SystemDrive & '\', or the functions won't work. SystemRestore.au3
    1 point
  24. This is not just "hidden" files and folders, but "super hidden" files and folders. By default "super hidden" files and folders are set not to be displayed, even when "hidden" files are set to be displayed. With these 4 functions you can super hide and unhide files and folders as well as set the system to show or hide these items. ; About: ; This is not just hidden files and folders, but "super hidden" ; files and folders. By default super hidden files and folders ; are set not to be displayed, even when hidden files are set to ; be displayed. With this you can super hide and unhide files and ; folders as well as set the system to show or hide these items. ; ; Super hide file or folder: ; _FileHide("C:\Users\Top Secret") ; ; Unhide super hidden file or folder: ; _FileShow("C:\Users\Top Secret") ; ; Set system to show super hidden files: ; _FileSuperHiddenShow() ; ; Set system to hide super hidden files: ; _FileSuperHiddenHide() ; Func _FileHide($f_path) FileSetAttrib($f_path,"+SH") EndFunc Func _FileShow($f_path) FileSetAttrib($f_path,"-SH") EndFunc Func _FileSuperHiddenShow() RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "SuperHidden", "REG_DWORD", "0x000001") EndFunc Func _FileSuperHiddenHide() RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "SuperHidden", "REG_DWORD", "0x000000") EndFunc
    1 point
×
×
  • Create New...