MattHiggs Posted January 14 Share Posted January 14 Hello all. Consider the following GUI script: expandcollapse popup#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 More sharing options...
Nine Posted January 14 Share Posted January 14 It is a question of privilege, you cannot drop on a higher app...Remove requireAdministrator “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
MattHiggs Posted January 14 Author Share Posted January 14 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 More sharing options...
MattHiggs Posted January 14 Author Share Posted January 14 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 More sharing options...
Nine Posted January 14 Share Posted January 14 Well it is working for me, so I have no idea why it does not work for you. You can start a program as admin with this : ShellExecute("notepad.exe", "", "", "runas") “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
InnI Posted January 15 Share Posted January 15 15 hours ago, Nine said: you cannot drop on a higher app This is possible if to use WinAPI See example in help file for _WinAPI_DragQueryFileEx() Nine 1 Link to comment Share on other sites More sharing options...
InnI Posted January 15 Share Posted January 15 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 More sharing options...
Nine Posted January 15 Share Posted January 15 @InnI Good catch. Forgot about. I use exactly this in my WCD-IPC. Funny... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now