Jump to content

GUI_EVENT_DROPPED not working only when script is compiled


Recommended Posts

Hello all.  Consider the following GUI script:
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.5 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 309, 221, 192, 124, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_GROUP,$DS_SETFOREGROUND), BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Pic1 = GUICtrlCreatePic("C:\Users\whiggs\Downloads\acutepuppy.jpg", 0, 0, 309, 221)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $GUI_EVENT_DROPPED
            $drop = @GUI_DragFile
            $ext = _GetFilenameExt ( $drop )
            MsgBox ( 1, "", $ext )
            If $ext = "lnk" Then
                $short = FileGetShortcut ( $drop )
                _ArrayDisplay ( $short )
            Else
                MsgBox ( 1, "", "Not a shortcut" )
            EndIf




    EndSwitch
WEnd

Func _GetFilename($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace ( StringReplace ( $sFilePath, "\", "\\"), "'", "\'" ) & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.FileName
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilename

Func _GetFilenameExt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace ( StringReplace ( $sFilePath, "\", "\\"), "'", "\'" ) & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Extension
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameExt

Func _GetFilenameInt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace ( StringReplace ( $sFilePath, "\", "\\"), "'", "\'" ) & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Name
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameInt

Func _GetFilenameDrive($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace ( StringReplace ( $sFilePath, "\", "\\"), "'", "\'" ) & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringUpper($oObjectFile.Drive)
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameDrive

Func _GetFilenamePath($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace ( StringReplace ( $sFilePath, "\", "\\"), "'", "\'" ) & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Path
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenamePath
Func IsFile($sFilePath)
    Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) = 0)
EndFunc   ;==>IsFile

As you can see, the script creates a simple GUI and a PIC control that covers the entirety of the GUI.  The GUI and the control have been configured to detect files that are dropped on it.  When I run this script within Scite (using Tools > go), the script runs exactly as I expect it would without issue.  However, when I compile the script into an executable, the $GUI_EVENT_DROPPED event does not appear to trigger (as far as I can tell) when a file is dropped onto the control.  Any idea why this might be happening?

 

Link to comment
Share on other sites

1 minute ago, Nine said:

It is a question of privilege, you cannot drop on a higher app...Remove requireAdministrator

Well...That is a problem.  I haven't gotten this far in the script yet, but I want to include functionality where, if the dropped file is an executable, the script will launch an exe with administrator privileges.  As far as I am aware, the only way that an autoit script can run an external executable as an administrator is to run the autoit script itself with elevated permissions.  If I am wrong, or if there is some workaround, I would appreciate a point in the right direction.

Link to comment
Share on other sites

12 minutes ago, Nine said:

It is a question of privilege, you cannot drop on a higher app...Remove requireAdministrator

Also.....this didn't work.  I removed the "require administrator" part, and the compiled script is still not working.

Link to comment
Share on other sites

Link to comment
Share on other sites

You need to uncomment this

; Allow WM_DROPFILES to be received from lower privileged processes (Windows Vista or later)
#cs
If IsAdmin() Then
        _WinAPI_ChangeWindowMessageFilterEx($g_hLabel, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
        _WinAPI_ChangeWindowMessageFilterEx($g_hLabel, $WM_DROPFILES, $MSGFLT_ALLOW)
EndIf
#ce
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...