Sideoutfan

Launch File Dropped Onto AutoIT

7 posts in this topic

I am very new to AutoIT and am trying to (if possible) have it so that when an application executable file is dropped onto (or into) AutoIT, that the installer file can run as an administrator account. I have an AutoIT setup up that takes the username of the currently logged in user, appends some text my company uses to identify an administrator username, then pulls in the password from an entry field and can launch the command prompt or registry as an administrator by clicking on a button in the AutoIT window. I believe I have the administrator functionality figured out, I just can't figure out how to apply those administrator credentials to launching a file dropped into the AutoIT window.

Share this post


Link to post
Share on other sites



I believe if you put #RequireAdmin in your script, any program started from within your script will be ran with admin rights as well.

Share this post


Link to post
Share on other sites

Thank you InunoTaishou and JohnOne.

 

This is what I have so far but it is not launching the executable file when I drop it on to there drop area. It is only displaying the path.

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

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

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <AutoItConstants.au3>
#include <EditConstants.au3>

GUICreate(" My GUI input acceptfile", 320, 180, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateTab(4, 0, 310, 200)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$USL = GUICtrlCreateLabel("Non-AA Username", 8, 30, 90, 17)
$UNI = GUICtrlCreateInput("", 108, 30, 113, 21)
$PW_Label = GUICtrlCreateLabel("Admin Password", 8, 60, 82, 17)
$PWField = GUICtrlCreateInput("", 108, 60, 105, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Domain = GUICtrlCreateLabel("Domain", 48, 90, 40, 17)
$DomList = GUICtrlCreateCombo("", 104, 90, 113, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Blanking this out")
$tab = GUICtrlCreateTabItem("newtab")
$drop = GUICtrlCreateInput("", 24, 120, 180, 50)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetBkColor(-1, 0xcccccc)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$tab = GUICtrlCreateTabItem("newtab1")
$tab = GUICtrlCreateTabItem("newtab2")
GUICtrlCreateTabItem("")
GUISetState()

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

        Case $drop
            $dropitem = GUICtrlRead($drop)
            $Username = GUICtrlRead($UNI)
            $Password = GUICtrlRead($PWField)
            $Domain = GUICtrlRead($DomList)
            RunAs("aa-" & $Username, $Domain, $Password, $RUN_LOGON_PROFILE, $dropitem)

    EndSwitch


WEnd

 

What are your thoughts on me improving this to perform what I am looking for? Launching the file that is dropped on to the drop area?

Share this post


Link to post
Share on other sites

I figured this out. I had to create a button to take the input act on the input in the drop space.

Share this post


Link to post
Share on other sites

Example with multiple files

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>

; Internal array, DO NOT USE directly. Instead call GetDropFiles() and/or IsValidDrop()
Global $g_aDropFiles[0]

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)

    ; IMPORTANT: If the system is using limited access rights
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_DROPFILES, $MSGFLT_ALLOW)
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)

    ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlCreateLabel('Drop Files Here...', 0, 0, 500, 500)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)

    Local $aDropped = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $GUI_EVENT_DROPPED
                ; Outdated approach to dropping a file
                ConsoleWrite('Single drop takes the last item in the array: ' & @GUI_DragFile & @CRLF)

                ; This always returns a valid array regardless of an error
                $aDropped = GetDropFiles()

                ; Was a valid drop?
                If IsValidDrop() Then
                    _ArrayDisplay($aDropped)
                EndIf

                ; Write the list of files to the console
                For $i = 1 To UBound($aDropped) - 1 ; $i is 1, because we need to skip the count in the first element. By iterating over the array this way, we avoid "out of bounds" errors
                    ConsoleWrite('File ' & $i & ' => ' & $aDropped[$i] & @CRLF)
                Next

                ; Empty line
                ConsoleWrite(@CRLF)

        EndSwitch
    WEnd

    ; Clean up the resources
    GUIDelete($hGUI)
EndFunc   ;==>Example

; Get the dropped list of files. NOTE: Destroys the global varibale on return
Func GetDropFiles()
    ; Empty array
    Local Const $aEmpty[0] = []
    Local $aReturn = $g_aDropFiles

    ; Destroy the global variable with the empty array
    $g_aDropFiles = $aEmpty

    Return $aReturn
EndFunc   ;==>GetDropFiles

; Use to determine if the drop was valid
Func IsValidDrop()
    Return UBound($g_aDropFiles) > 0
EndFunc   ;==>IsValidDrop

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam

    If $iMsg = $WM_DROPFILES Then
        $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam)5

        If Not UBound($g_aDropFiles) Then
            ; Empty array
            Local Const $aEmpty[0] = []

            ; Set with the empty array
            $g_aDropFiles = $aEmpty
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

 


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


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