Jump to content

Recommended Posts

#include <WinAPISys.au3>
#include <WindowsConstants.au3>

_WinAPI_ChangeWindowMessageFilterEx ( $hWnd, $iMsg, $iAction )

;_WinAPI_ChangeWindowMessageFilterEx( $hWnd, $WM_DROPFILES, $MSGFLT_ALLOW)
;_WinAPI_ChangeWindowMessageFilterEx( $hWnd, $WM_COPYDATA, $MSGFLT_ALLOW)
;_WinAPI_ChangeWindowMessageFilterEx( $hWnd, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)



Opt("TrayAutoPause", 0)
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
Global $AppWindows = GUICreate("Dao Van Trong  - Trong.CF", 320, 50, -1, -1, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
Global $AppTitle = GUICtrlCreateLabel("=== Drag and drop UAC ===", 56, 0, 210, 25, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 800)
Global $AppTask = GUICtrlCreateLabel("Drag and drop files here ", 56, 24, 220, 17, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 500)
Global $xCLOSE = GUICtrlCreateButton("X", 308, 0, 12, 12, BitAND($BS_MULTILINE, $BS_VCENTER, $BS_FLAT))
_WinAPI_ChangeWindowMessageFilterEx($AppWindows, $WM_DROPFILES, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($AppWindows, $WM_COPYDATA, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($AppWindows, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
Global $__aDropFiles
Local $nMsg
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
            If $__aDropFiles[0] > 0 Then
                For $i = 1 To $__aDropFiles[0]
                    ConsoleWrite($__aDropFiles[$i] & @CRLF)
                    GUICtrlSetData($AppTask, $__aDropFiles[$i])
        Case $GUI_EVENT_CLOSE, $xCLOSE
Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $ilParam
    Switch $iMsg
        Case $WM_DROPFILES
            Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)
            If IsArray($aReturn) Then
                $__aDropFiles = $aReturn
                Local $aError[1] = [0]
                $__aDropFiles = $aError
EndFunc   ;==>WM_DROPFILES


Edited by Trong


Link to post
Share on other sites

@Trong: would you mind restating (in your first post) what the problem is that you've solved?

_WinAPI_ChangeWindowMessageFilterEx appears to be very useful ... but are you working only with AU3 scripts? ... or have you tried it with other applications?  If so, what is your method for doing that?

Thanks for opening this topic.


Link to post
Share on other sites

His problem was, he could not drop files on his GUI's ListView. Script requires Admin privileges (#RequireAdmin). I found after @AdmiralAlex post this solution:

;found https://www.autoitscript.com/forum/topic/124406-drag-and-drop-with-uac/
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode", 1)

Global $DropFilesArr[1]
Global $FilesAllowedMask[4] = [3, ".txt", ".exe", "D"]

$mainFrm = GUICreate("Drop Multiple Files to LV Demo", 500, 400, -1, -1, -1, $WS_EX_ACCEPTFILES+$WS_EX_TOPMOST)
_ChangeWindowMessageFilterEx($mainFrm, 0x233, 1)
_ChangeWindowMessageFilterEx($mainFrm, $WM_COPYDATA, 1)
_ChangeWindowMessageFilterEx($mainFrm, 0x0049, 1)

GUISetOnEvent($GUI_EVENT_CLOSE, "MainEvents")
GUISetOnEvent($GUI_EVENT_DROPPED, "MainEvents")

GUIRegisterMsg(0x233, "WM_DROPFILES_FUNC")

GUICtrlCreateLabel("Drag to the List View some file(s)", 60, 20)

$ListView = GUICtrlCreateListView("Col1", 50, 50, 400, 300, -1, $WS_EX_CLIENTEDGE)


While 1

Func MainEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            $NotValidExtPath = ""
            $ValidExtCount = 0
            For $i = 1 To UBound($DropFilesArr)-1
                $ValidExtCount += 1
                GUICtrlCreateListViewItem($DropFilesArr[$i], $ListView)
            If $ValidExtCount > 0 Then GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)

Func _IsValidExt($sPath)
    For $i = 1 To $FilesAllowedMask[0]
        If StringRight($sPath, 4) = $FilesAllowedMask[$i] And _
            Not StringInStr(FileGetAttrib($sPath), $FilesAllowedMask[$i]) Then Return True
    Return False

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
            DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $DropFilesArr[$i + 2]
        $DropFilesArr[$i+1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    $DropFilesArr[0] = UBound($DropFilesArr)-1

Func _ChangeWindowMessageFilterEx($hWnd, $iMsg, $iAction)
    Local $aCall = DllCall("user32.dll", "bool", "ChangeWindowMessageFilterEx", _
            "hwnd", $hWnd, _
            "dword", $iMsg, _
            "dword", $iAction, _
            "ptr", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1

When you remove Lines 12-14 which uses the func _ChangeWindowMessageFilterEx you have the problem similar to @Tong's. When you want to use this func in a other programming language you have to implement the DLL-call for User32.dll.

Link to post
Share on other sites

His problem was, he could not drop files on his GUI's ListView. Script requires Admin privileges (#RequireAdmin). I found after @AdmiralAlex post this solution:

    Local $aCall = DllCall("user32.dll", "bool", "ChangeWindowMessageFilterEx", _

Windows 7 or later Only ChangeWindowMessageFilterEx 

XP and All :

#include <WinAPISys.au3>
_WinAPI_ChangeWindowMessageFilterEx ( $hWnd, $iMsg, $iAction )



Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Doniel
      Hi there! 😃
      I've 2 simple scripts:
      Script 1 starts script 2 Script 1 gets executed with normal user rights (un-elevated) Script 2 contains an #RequireAdmin and therefor can only start elevated I want to read the output of script 2 with script 1 AND have the UAC of script 2 being activated as fullscreen Script 1 (Scripts location is the same as script 2 that I'm running with Run()
      Local $iPID, $sOutput $iPID = Run(@ComSpec & " /c " & "C:\Entwicklung\Autoit\Test\Temp.exe", @ScriptDir, @SW_HIDE, 0x2) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) StdioClose($iPID) ConsoleWrite($sOutput) MsgBox(1, 1, 1) Script 2 (compiled as Temp.exe)
      #RequireAdmin ConsoleWrite("Return") MsgBox(1,1,"ADMIN") Now my problems are the following:
      Without the #RequireAdmin I can read the output with no problem, but not with the #RequireAdmin ($sOutput is empty) Using @SW_HIDE in the Run() command makes the UAC always start minimized (see attached picture) and the admin has to always manually click on the icon to enter his credentials since the UAC doesn't start in fullscreen. Here and on a few other sites they explain that the program launching the elevated program NEEDS to be activated in order to directly show the UAC fullscreen and not minimized. Using @SW_SHOW would get rid of the problem, BUT that leaves me with an ugly cmd.exe floating the whole time while the elevated script ist running. And my questions to that I'm seeking an answer for are:
      Problem 1: Is it just not possible to read from an elevated program with an un-elevated user/script? I also get the Access Denied if I press No on the UAC as an Output in $sOutput (Guess since its's still un-elevated) Problem 2: Is there a way to either make the floating black and blank cmd.exe being moved to the background and be non visible to the user OR to somehow bring the minimized UAC to the foreground/fullscreen? What I already tried and what didn't help me:
      $iPID = Run(@ComSpec & " /c " & "C:\Entwicklung\Autoit\Test\Temp.exe", @ScriptDir, @SW_HIDE, 0x2) While Not WinExists("Temp.exe erfordert Ihre Berechtigung") ConsoleWrite(1) WEnd WinActivate("Temp.exe erfordert Ihre Berechtigung") WinSetState("Temp.exe erfordert Ihre Berechtigung", WinGetText("Temp.exe erfordert Ihre Berechtigung"), @SW_SHOW) WinSetState("Temp.exe erfordert Ihre Berechtigung", WinGetText("Temp.exe erfordert Ihre Berechtigung"), @SW_MAXIMIZE) WinSetState("Temp.exe erfordert Ihre Berechtigung", WinGetText("Temp.exe erfordert Ihre Berechtigung"), @SW_ENABLE) The While-Loops helps a lot and also stops after a second or so (► Stops to write ones (1)). That means that the actual "window" of the UAC is found, but all the WinXXX functions don't do anything and the UAC stays minimized. I also tried to minimized/move the cmd.exe to the background with WinActivate() and WinSetState() with no success.
      $iPID = ShellExecute("C:\Entwicklung\Autoit\Test\Temp.exe", "", @ScriptDir, "open", @SW_HIDE) Using ShellExecute() instead of Run() completely solves the UAC to fullscreen problem BUT I haven't found a consistent way to read the output of ShellExecute(). Neither here on the forum nor somewhere else. If I'd be possible to read the output from ShellExecute() then all my problems would be solved at once!
      Also tried a few more things and playing with some parameters but everything with no success.
      I'd really love some help and support here from you.
      Thanks in advance!

    • By rudi
      When a non compiled AU3 script is run with #RequireAdmin, then if the UAC prompt can be authorized due to the fact, that the currently loggedon user has local admin rights, then the macro @UserProfileDir correctly reflects the profile dir of the user of the windows logon session.
      When the script with #RequireAdmin is started by a "normal user" without local admin rights, and I use a domain admin account to authorize the UAC prompt, then @UserProfileDir reflects the profile dir belonging to the AD-Admin account.
      As the script originally was started using the "regular user" I'm wondering, if there is a chance to "pass" the original user's @UserProfileDir to the UAC elevated script?
      As playing around with this feature I realize, that I basically don't know the exact mechanism of the UAC elevation authorization process:
      The script is started by right mouse click, execute script This is invoking e.g. "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Users\Rudi\Desktop\test.au3" as by this registy value: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\AutoIt3Script\Shell\Run\Command] @="\"C:\\Program Files (x86)\\AutoIt3\\AutoIt3.exe\" \"%1\" %*" But what I honestly don't know is, how does the UAC propt interact in the program startup? I guess, that Autoit3.exe is parsing the AU3 source, is seeing the #RequireAdmin and then "relaunches itself with the AU3 as %1" requesting UAC elevated rights "from windows"??? With Process Explorer I can see, that The commandline then is this one with a "!" before "%1"
      "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" !"C:\Users\Rudi\Desktop\test.au3"  It it should be something like this, then it might be possible to pass the original @UserProfileDir to the second, UAC elevated "Startup"??? <edit>
      I just noticed:
      When I use "WIN+R" and then directly use the command line, I see in Process Explorer, ...
      "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" !"C:\Users\Rudi\Desktop\test.au3"
      ... then this script with #RequireAdmin is started *WITHOUT* UAC elevation.
      Guessing, that this ! is just reverting #RequireAdmin I tried the "opposite" one as well:
      AU3 script without #RequireAdmin Starting with "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" !"C:\Users\Rudi\Desktop\test.au3" does not invoke UAC elevation prompt. So to me it looks like, this ! is a "status flag from Autoit3.exe to Autoit3.exe", that the elevation process was done already? amazing...
      the topic Autoit on Windows Vista is telling no details of  this UAC process...
      Regards, Rudi.
    • By griefman
      Hi everyone,
      i am writing to you after a very long struggle i had while trying to figure out how to send a simple click inside a virtual machine running in vmware workstation 14.
      i have an autoit script running on my host machine watching for the UAC prompt to be displayed in a running vm. Both the host and the guest OS are Windows 10. This script worked perfectly with virtual box. It recognized the UAC prompt and clicked inside and the UAC was accepted. Since i switched to VMware Workstation 14, the script no longer clicks inside the VM successfully. It acts as if it clicks, but it doesn't. 
      I tried sending key combinations instead of a click, so that the VM can grab the input, but it also did not work. Every attempt that i made to send clicks or keys from the host inside the VM did not work. I tried using:
      I also noticed that while the cursor moves to the target which has to be cilcked when my vmware worstation window is not focused, it even doesn't do that when i WinActivate the vmware workstation window first.
      Did anyone experience such an issue, or maybe could give me a hint, what else i could use to send a key combination or a mouse click in a vmware workstation 14 pro guest window?
      here is my code, which works with virtualbox:
      #AutoIt3Wrapper_Icon=".\uac.ico" #include <ImageSearchSubrogated.au3> FileInstall(".\ImageSearchDLL.dll", ".\ImageSearchDLL.dll", 0) FileInstall(".\UAC_ginloSetup.bmp", ".\UAC_ginloSetup.bmp", 0) FileInstall(".\UAC_Yes.bmp", ".\UAC_Yes.bmp", 0) ; set global variables for the coordinates, which should be delivered global $x1 = 0, $y1 = 0 global $x2 = 0, $y2 = 0 global $counter1 = 0 global $counter2 = 0 global $sleep = 10000 global $smallSleep = 5000 ; execute the script in a loop, so that it will hopefully recover from some unexpected errors While $counter1 < 1 checkForImage() WEnd #cs ------------ Functions #ce ------------ Func checkForImage() While $counter2 < 1 ; search for the UAC in the entire screen - 2 screens supported local $searchUac = _ImageSearchArea('UAC_ginloSetup.bmp', 1, -2568, -8, 5136, 1440, $x1, $y1, 0) If $searchUac = 1 Then ; if the UAC was found search for the Yes button in a an area 200 x 200 from the middle of the found UAC image local $searchYes = _ImageSearchArea('UAC_Yes.bmp', 1, $x1, $y1, $x1 + 200, $y1 + 200, $x2, $y2, 0) If $searchYes = 1 Then ; if the Yes button was found click it and pause the script for $sleep seconds MouseClick("left", $x2, $y2, 1,0) Sleep($sleep) Else ; if the Yes button was not found retry from the beginning in $smallSleep seconds MsgBox(0, "UAC found error", "UAC was found but the 'Yes' button was not found. Script will retry in " & $smallSleep & " seconds.", $smallSleep) EndIf ; another way to accept the UAC - via shortcut ;Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}") ;Send("!y") Else ; if UAC was not found try again in $sleep seconds Sleep($sleep) EndIf WEnd ; if some error occured which expired the loop, pause the script for $sleep seconds MsgBox(0, "Error", "Some Error expired the timer and the script could not recover. The script will restart in " & $sleep & " seconds.", $sleep) EndFunc  
    • By ur
      I saw few UDFs related to IE and Firefox to automate tasks related to these browsers.
      But is it possible to automate tasks like drag and drop in the website.?
      Like in the below video.
      If not can you tell me some alternatives, as it is not possible in selenium as I heard.
    • By perlabsrat
      I found a good drag and drop example here: https://www.autoitscript.com/forum/topic/28062-drop-multiple-files-on-any-control/
      I have been searching but not finding a way to do a variant of this example.
      I want to have a form with 2 or more list box controls on the form that have $GUI_DROPACCEPTED enabled. I then want to be able to drop separate groups of files on each list box  so that I have 2 separate list of dropped items that I can act upon independently rather than this example which only has one target.
      I have modified the example to add the 2nd list box but I am not sure how to determine which control hwnd got the drop event and then only add the files to that list box. In the current example both controls add the files to $hList1
      Apparently $hWnd  in WM_DROPFILES_FUNC() is not the control that triggers the event as I compared its value to the hwnd of each control.
      hwnd from $hList1 = 0x002F0BB8 hwnd from $hList2 = 0x003C06E0 hwnd from WM_DROPFILES_FUNC = 0x002F1180 hwnd from WM_DROPFILES_FUNC = 0x002F1180  
      Any ideas?

      ;Example from https://www.autoitscript.com/forum/topic/28062-drop-multiple-files-on-any-control/ #include <GUIConstants.au3> ;~ Global $WM_DROPFILES = 0x233 Global $gaDropFiles[1], $str = "" ### Koda GUI section start ### ;~ $hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)) ;~ $hList = GUICtrlCreateList("", 5, 5, 390, 190) ;~ GUICtrlSetState (-1, $GUI_DROPACCEPTED) Global $hGUI = GUICreate("Test", 573, 419, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) Global $hList1 = GUICtrlCreateList("", 5, 5, 390, 188) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetData(-1, "List1") Global $hList2 = GUICtrlCreateList("", 42, 205, 390, 188) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetData(-1, "List2") ConsoleWrite("hwnd from $hList1 = " & GUICtrlGetHandle($hList1) & @CRLF) ConsoleWrite("hwnd from $hList2 = " & GUICtrlGetHandle($hList2) & @CRLF) GUISetState(@SW_SHOW) ### Koda GUI section end ### GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED $str = "" For $i = 0 To UBound($gaDropFiles) - 1 $str &= "|" & $gaDropFiles[$i] Next GUICtrlSetData($hList1, $str) EndSwitch WEnd Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam) ConsoleWrite("hwnd from WM_DROPFILES_FUNC = " & $hGUI & @CRLF) Local $nSize, $pFileName Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i + 1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) $pFileName = 0 Next EndFunc ;==>WM_DROPFILES_FUNC  
  • Create New...