Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/26/2016 in all areas

  1. Here a small function to mark a region on the desktop and capture that region to a bitmap handle or to the clipboard: #include-once #include <Clipboard.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> #Region Example ;capture manual coordinates FileDelete(@ScriptDir & "\Captured.bmp") Global $hHBitmap = _WinAPI_MarkScreenRegionAndCapture(0, False, True, 0, 0, 99, 99) _WinAPI_SaveHBITMAPToFile(@ScriptDir & "\Captured.bmp", $hHBitmap) _WinAPI_DeleteObject($hHBitmap) If FileExists(@ScriptDir & "\Captured.bmp") Then ShellExecute(@ScriptDir & "\Captured.bmp") ;save the captured bitmap to a file FileDelete(@ScriptDir & "\Captured.bmp") Global $hHBitmap = _WinAPI_MarkScreenRegionAndCapture() _WinAPI_SaveHBITMAPToFile(@ScriptDir & "\Captured.bmp", $hHBitmap) _WinAPI_DeleteObject($hHBitmap) If FileExists(@ScriptDir & "\Captured.bmp") Then ShellExecute(@ScriptDir & "\Captured.bmp") ;copy captured bitmap to clipboard Switch _WinAPI_MarkScreenRegionAndCapture(1, True) Case 1 MsgBox($MB_ICONINFORMATION, "Information", "Marked region was properly captured to clipboard!", 30) Case 0 MsgBox($MB_ICONERROR, "ERROR", "An error has occured!", 30) EndSwitch #EndRegion ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_MarkScreenRegionAndCapture ; Description ...: Selected area on desktop will be captured and save to clipbord or GDI bitmap handle will be returned. ; Syntax ........: _WinAPI_MarkScreenRegionAndCapture([$iFillMode = 0[, $bClipboard = True]]) ; Parameters ....: $iFillMode - [optional] an integer value. Default is 0. ; 0: marked area filled with solid color ; 1: marked area filled with hatch pattern ($HS_DIAGCROSS) ; 2: marked area without any fill pattern / color - only red border ; $bClipboard - [optional] a boolean value. Default is False. If True then no GDI bitmap handle will be returned. ; If false then GDI bitmap handle will be returned. ; $bManual - [optional] a boolean value. Default is False. If True manual capturing is activated. ; $iX1 - [optional] an integer value. Default is 0. If $bManual is true enter the x1 screen pos. ; $iY1 - [optional] an integer value. Default is 0. If $bManual is true enter the Y1 screen pos. ; $iX2 - [optional] an integer value. Default is 0. If $bManual is true enter the x2 screen pos. ; $iY2 - [optional] an integer value. Default is 0. If $bManual is true enter the y2 screen pos. ; Return values .: 0 / 1 / -1 / GDI bitmap handle ; Author ........: UEZ ; Version .......: 0.92 build 2017-01-22 ; Modified ......: ; Remarks .......: Do not forget to dispose returned GDI bitmap handle for non clipboard mode using _WinAPI_DeleteObject! ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_MarkScreenRegionAndCapture($iFillMode = 0, $bClipboard = False, $bManual = False, $iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0) If @OSBuild > 6299 Then ;https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx DllCall("Shcore.dll", "long", "PROCESS_DPI_AWARENESS", 1) ;PROCESS_SYSTEM_DPI_AWARE = 1 (https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx) Else DllCall("User32.dll", "bool", "SetProcessDPIAware") EndIf Local $iOld = AutoItSetOption("MouseCoordMode", 1) If Not $bManual Then Local Const $hDesktop = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hDesktop) ;should work also on multi screens Local Const $iW = $aFullScreen[2], $iH = $aFullScreen[3] Local Const $hGUI_Screencapture = GUICreate("", $iW, $iH, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetState(@SW_SHOW, $hGUI_Screencapture) Local Const $hDC = _WinAPI_GetDC($hGUI_Screencapture) Local Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC) Local Const $hBitmapGDI = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI) Local $tSize = DllStructCreate($tagSIZE) $tSize.x = $iW $tSize.y = $iH Local $tSource = DllStructCreate($tagPOINT) Local $tBlend = DllStructCreate($tagBLENDFUNCTION) $tBlend.Alpha = 0xFF $tBlend.Format = 1 Local $tDest = DllStructCreate($tagPOINT), $pPoint = DllStructGetPtr($tDest) $tDest.x = $aFullScreen[0] $tDest.y = $aFullScreen[1] Local Const $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x0000FF) Local Const $hPen_Orig = _WinAPI_SelectObject($hGfxDC, $hPen) Local $hBrush, $iAlpha2, $iFlag $iFillMode = $iFillMode > 2 ? 2 : $iFillMode < 0 ? 0 : $iFillMode Switch $iFillMode Case 0 $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, 0x808080) $iAlpha2 = 0xA0 $iFlag = $ULW_ALPHA Case 1 $hBrush = _WinAPI_CreateBrushIndirect($BS_HATCHED, 0x808000, $HS_DIAGCROSS) $iAlpha2 = 0x30 $iFlag = $ULW_ALPHA Case 2 $hBrush = _WinAPI_CreateBrushIndirect($BS_HOLLOW, 0x000000) $iAlpha2 = 0xFF ;not needed $iFlag = $ULW_COLORKEY EndSwitch Local $hBrush_Orig = _WinAPI_SelectObject($hGfxDC, $hBrush) Else If Not BitOr($iX1, $iX2, $iY1, $iY2) Then Return SetError(4, 0, 0) EndIf Local $aMPos[5], $aMPos_old[4], $tRECT = _WinAPI_CreateRect(0, 0, 0, 0) Do If $bManual Then $aMPos[2] = 1 Else GUISetCursor(16, 1, $hGUI_Screencapture) $aMPos = GUIGetCursorInfo($hGUI_Screencapture) $aMPos_old[0] = $aMPos[0] $aMPos_old[1] = $aMPos[1] $aMPos_old[2] = MouseGetPos(0) $aMPos_old[3] = MouseGetPos(1) EndIf Switch $aMPos[2] Case 0 ;display crosshair _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $CAPTUREBLT) _WinAPI_DrawLine($hGfxDC, $tDest.x, $aMPos[1], $iW, $aMPos[1]) _WinAPI_DrawLine($hGfxDC, $aMPos[0], $tDest.y, $aMPos[0], $iH) _WinAPI_UpdateLayeredWindow($hGUI_Screencapture, $hDC, $tDest, $tSize, $hGfxDC, $tSource, 0, $tBlend, $ULW_COLORKEY) Case 1 ;capture selected region If Not $bManual Then $tBlend.Alpha = $iAlpha2 While $aMPos[2] ;mark region GUISetCursor(14, 1, $hGUI_Screencapture) ;WinGetHandle(AutoItWinGetTitle())) $aMPos = GUIGetCursorInfo($hGUI_Screencapture) _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $CAPTUREBLT) ;clear bitmap ;draw rectangle $tRECT.Left = $aMPos_old[0] $tRECT.Top = $aMPos_old[1] $tRECT.Right = $aMPos[0] $tRECT.Bottom = $aMPos[1] _WinAPI_Rectangle($hGfxDC, $tRECT) If $iFillMode <> 2 Then _WinAPI_InvertRect($hGfxDC, $tRECT) _WinAPI_UpdateLayeredWindow($hGUI_Screencapture, $hDC, $tDest, $tSize, $hGfxDC, $tSource, 0, $tBlend, $iFlag) Sleep(10) WEnd _WinAPI_SelectObject($hGfxDC, $hObjOld) _WinAPI_ReleaseDC($hGUI_Screencapture, $hDC) _WinAPI_DeleteDC($hGfxDC) _WinAPI_DeleteObject($hBitmapGDI) _WinAPI_SelectObject($hGfxDC, $hPen_Orig) _WinAPI_DeleteObject($hPen) _WinAPI_SelectObject($hGfxDC, $hBrush_Orig) _WinAPI_DeleteObject($hBrush) GUIDelete($hGUI_Screencapture) ;capture region $aMPos[0] = MouseGetPos(0) $aMPos[1] = MouseGetPos(1) Else $aMPos_old[2] = $iX1 $aMPos_old[3] = $iY1 $aMPos[0] = $iX2 $aMPos[1] = $iY2 EndIf Local Const $hDC_Region = _WinAPI_GetDC(0) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Region) Local Const $iW_Region = Abs($aMPos[0] - $aMPos_old[2]) + 1, $iH_Region = Abs($aMPos[1] - $aMPos_old[3]) + 1 Local $hHBitmap_Captured = _WinAPI_CreateCompatibleBitmap($hDC_Region, $iW_Region, $iH_Region) $hObjOld = _WinAPI_SelectObject($hMemDC, $hHBitmap_Captured) _WinAPI_BitBlt($hMemDC, 0, 0, $iW_Region, $iH_Region, $hDC_Region, _ $aMPos[0] > $aMPos_old[2] ? $aMPos_old[2] : $aMPos[0], _ $aMPos[1] > $aMPos_old[3] ? $aMPos_old[3] : $aMPos[1], BitOR($SRCCOPY, $CAPTUREBLT)) Local $hHBitmap_Clipboard = _WinAPI_CopyImage($hHBitmap_Captured, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_SelectObject($hHBitmap_Captured, $hObjOld) _WinAPI_DeleteDC($hHBitmap_Captured) _WinAPI_ReleaseDC(0, $hDC_Region) AutoItSetOption("MouseCoordMode", $iOld) If $bClipboard Then ;put captured region to clipboard If Not _ClipBoard_Open(0) Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(1, 0, 0) EndIf If Not _ClipBoard_Empty() Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(2, 0, 0) EndIf Local Const $hCP = _ClipBoard_SetDataEx($hHBitmap_Clipboard, $CF_BITMAP) If Not $hCP Or @error Then _WinAPI_DeleteObject($hHBitmap_Clipboard) Return SetError(3, 0, 0) EndIf _ClipBoard_Close() _WinAPI_DeleteObject($hHBitmap_Clipboard) Return 1 Else Return $hHBitmap_Clipboard EndIf EndSwitch Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_SelectObject($hGfxDC, $hObjOld) _WinAPI_ReleaseDC($hGUI_Screencapture, $hDC) _WinAPI_DeleteDC($hGfxDC) _WinAPI_DeleteObject($hBitmapGDI) _WinAPI_SelectObject($hGfxDC, $hPen_Orig) _WinAPI_DeleteObject($hPen) GUIDelete($hGUI_Screencapture) AutoItSetOption("MouseCoordMode", $iOld) Return -1 EndSwitch Until False EndFunc ;==>_WinAPI_MarkScreenRegionAndCapture Might be useful... Download: _WinAPI_MarkScreenRegionAndCapture.au3 (same as above in the code box) Tested only on Win10 x64 but should work also on other Window versions. If not please reply.
    4 points
  2. Post a runnable script... Kylomas Edit..display $afilters after your sre to build it. I dont think you are getting what you think you are...
    1 point
  3. Thanks for testing. Thanks also to you for testing . You mean that image probably: http://img.timeinc.net/time/pictures_of_the_year/pictures_of_the_year_28.jpg
    1 point
  4. Terenz

    Set Acl permissions UDF

    New version of _GetSidStruct Func _GetSidStruct($AccountName) If $AccountName = 'TrustedInstaller' Then $AccountName = 'NT SERVICE\TrustedInstaller' Select Case $AccountName = 'Everyone' Return _StringSidToSid('S-1-1-0') Case $AccountName = 'Authenticated Users' Return _StringSidToSid('S-1-5-11') Case $AccountName = 'System' Return _StringSidToSid('S-1-5-18') Case $AccountName = 'Administrators' Return _StringSidToSid('S-1-5-32-544') Case $AccountName = 'Users' Return _StringSidToSid('S-1-5-32-545') Case $AccountName = 'Guests' Return _StringSidToSid('S-1-5-32-546') Case $AccountName = 'Power Users' Return _StringSidToSid('S-1-5-32-547') Case $AccountName = 'Local Authority' Return _StringSidToSid('S-1-2') Case $AccountName = 'Creator Owner' Return _StringSidToSid('S-1-3-0') Case $AccountName = 'NT Authority' Return _StringSidToSid('S-1-5-1') Case $AccountName = 'Restricted' Return _StringSidToSid('S-1-5-12') Case StringRegExp($AccountName, '\A(S-\d(-\d+){2,14})\z') ; is a SID Return _StringSidToSid($AccountName) Case Else ; is an account name Local $SID = _LookupAccountName($AccountName) Return _StringSidToSid($SID) EndSelect EndFunc ;==>_GetSidStruct
    1 point
  5. Terenz

    Set Acl permissions UDF

    Adam about the redirection, you are correct the script always take another DLL instead of that i have put in the path. You second script at post #143 work "partially" fine. _GetObjectOwner give me the correct owner and also the SID is valid, i have check with CMD "sc showsid TrustedInstaller" If i put: FileMove("C:\Windows\System32\aaclient.dll", @ScriptDir) After _EditObjectPermissions the file is moved in the @ScriptDir ( just for test, for see if the permission are all correct ) and until that everything goes in the right direction. The problem is here: $iRet = _SetObjectSecurity(@ScriptDir & "\aaclient.dll", $SE_FILE_OBJECT, $DACL_SECURITY_INFORMATION, 0, 0, $pDACL, 0) Global $iRet1 = _SetObjectOwner(@ScriptDir & "\aaclient.dll", $SE_FILE_OBJECT, $sOwner) MsgBox(0, '', 'Restore all permissions' & @CRLF & @CRLF & _ '_SetObjectSecurity return value: ' & $iRet & @CRLF & _ '_SetObjectOwner return value: ' & $iRet1 & @error & @CRLF & @CRLF & _ 'Check the file permissons before closing the message box.') It restore the original permission with _SetObjectSecurity but _SetObjectOwner FAIL! Give me 0 and the error is 87 Searching about this 87 i have see that is SetNamedSecurityInfo and the error is "Invalid Parameter". What? What parameter is invalid? P.S If i change "TrustedInstaller" with "Administrators" group like owner _SetObjectOwner can correct restore the original owner after the FileMove so there is a problem with "TrustedInstaller" inside the script, maybe in _GetSidStruct? With "Administrators" SID return value inside _SetObjectOwner are: $SID = "" $pSID = 0x034B7588 With "TrustedInstaller" SID taken from _GetObjectOwner $SID = 0 $pSID = 0 That's why error 87, $pSID is 0 SetNamedSecurityInfo fail and i really don't know why. This work fine: _SetObjectOwner(@ScriptDir & "\aaclient.dll", $SE_FILE_OBJECT, "TrustedInstaller") This NOT: _SetObjectOwner(@ScriptDir & "\aaclient.dll", $SE_FILE_OBJECT, "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464") So the problem is the SID processed by _SetObjectOwner , i prefer don't use the Owner name in any case. Thanks for your help, i apprecciate it. PROBLEM FOUND! Was the damn, stupid StringRegExp, hours lost for this. The original _GetSidStruct identyfy the SID like a NAME! Here you can see the difference between old and my version: _GetSidStruct_Original("S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464") _GetSidStruct_New("S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464") Func _GetSidStruct_Original($AccountName) If $AccountName = 'TrustedInstaller' Then $AccountName = 'NT SERVICE\TrustedInstaller' If $AccountName = 'Everyone' Then ;~ Return _StringSidToSid('S-1-1-0') ElseIf $AccountName = 'Authenticated Users' Then ;~ Return _StringSidToSid('S-1-5-11') ElseIf $AccountName = 'System' Then ;~ Return _StringSidToSid('S-1-5-18') ElseIf $AccountName = 'Administrators' Then ;~ Return _StringSidToSid('S-1-5-32-544') ElseIf $AccountName = 'Users' Then ;~ Return _StringSidToSid('S-1-5-32-545') ElseIf $AccountName = 'Guests' Then ;~ Return _StringSidToSid('S-1-5-32-546') ElseIf $AccountName = 'Power Users' Then ;~ Return _StringSidToSid('S-1-5-32-547') ElseIf $AccountName = 'Local Authority' Then ;~ Return _StringSidToSid('S-1-2') ElseIf $AccountName = 'Creator Owner' Then ;~ Return _StringSidToSid('S-1-3-0') ElseIf $AccountName = 'NT Authority' Then ;~ Return _StringSidToSid('S-1-5-1') ElseIf $AccountName = 'Restricted' Then ;~ Return _StringSidToSid('S-1-5-12') ElseIf StringRegExp($AccountName, '\A(S-1-\d+(-\d+){0,5})\z') Then MsgBox(0,0,"SID") Else MsgBox(0,0,"NAME") EndIf EndFunc ;==>_GetSidStruct Func _GetSidStruct_New($AccountName) If $AccountName = 'TrustedInstaller' Then $AccountName = 'NT SERVICE\TrustedInstaller' Select Case $AccountName = 'Everyone' ;~ Return _StringSidToSid('S-1-1-0') Case $AccountName = 'Auticated Users' ;~ Return _StringSidToSid('S-1-5-11') Case $AccountName = 'System' ;~ Return _StringSidToSid('S-1-5-18') Case $AccountName = 'Administrators' ;~ Return _StringSidToSid('S-1-5-32-544') Case $AccountName = 'Users' ;~ Return _StringSidToSid('S-1-5-32-545') Case $AccountName = 'Guests' ;~ Return _StringSidToSid('S-1-5-32-546') Case $AccountName = 'Power Users' ;~ Return _StringSidToSid('S-1-5-32-547') Case $AccountName = 'Local Authority' ;~ Return _StringSidToSid('S-1-2') Case $AccountName = 'Creator Owner' ;~ Return _StringSidToSid('S-1-3-0') Case $AccountName = 'NT Authority' ;~ Return _StringSidToSid('S-1-5-1') Case $AccountName = 'Restricted' ;~ Return _StringSidToSid('S-1-5-12') Case StringRegExp($AccountName, '\A(S-\d(-\d+){2,14})\z') ; is a SID ;~ Return _StringSidToSid($AccountName) MsgBox(0, 0, "SID") Case Else ; is an account name ;~ Local $SID = _LookupAccountName($AccountName) ;~ Return _StringSidToSid($SID) MsgBox(0, 0, "NAME") EndSelect EndFunc ;==>_GetSidStruct2 On the next post the working function.
    1 point
  6. AutoBert

    is mouse over GUI?

    This func does the job: Func _MouseIsOverHWnd($hWnd) Local $bMouseOver If not WinActive($hWnd) then return False Local $aMousePos = MouseGetPos() Local $aWinPos = WinGetPos($hWnd) if ($aMousePos[0] < $aWinPos[0] Or $aMousePos[0] > $aWinPos[0] + $aWinPos[2]) Or ($aMousePos[1] < $aWinPos[1] Or $aMousePos[1] > $aWinPos[1] + $aWinPos[3]) Then $bMouseOver = False Else $bMouseOver = True EndIf Return $bMouseOver EndFunc ;==>_MouseIsOverHWnd
    1 point
  7. There you go: ;Copy a certain column from Excel sheet to an Array Func _ReadFromExcel($column) Local $data Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Open", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, $xlsPath) If @error Then Switch @error Case 2 MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen", "Specified Filepath does not exist" & @CRLF & "@error = " & @error & ", @extended = " & @extended) Case 3 MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen", "Error opening the selected Excel file." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Case 4 MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen", "Readwrite access could not be granted. Workbook might be open by another users/task." & @CRLF & "@error = " & @error & ", @extended = " & @extended) EndSwitch ProcessClose("EXCEL.exe") Else $data = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns($column & ":" & $column), 2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) EndIf Return $data EndFunc Just call it like: $xlsPath = "Excel.xls" ; Path to your excelsheet $aExcelCol = _ReadFromExcel("A")
    1 point
  8. At least when wanting to kill Ecel 2007, "WinKill" works only if followed by "ProcessClose"
    1 point
  9. Marlo

    Sum of Numbers Entered

    Dan beat me to it with the StringSplit method Dim $sNumbers = "123456789" ;Our numbers we want to add together. Dim $aNumbers = StringSplit($sNumbers, "") ;split te numbers up into an array so: [1] = 1, [2] = 2, etc Dim $iSum ;this variable will hold the answer For $I = 1 To $aNumbers[0] ;Go through each number in our array and add it to our sum $iSum += $aNumbers[$I] Next MsgBox(64, "Addition", $sNumbers & " added together is " & $iSum) ;Display the answer
    1 point
×
×
  • Create New...