Dialog messages not handled when opening dialog from system tray entry - autoit

I have an AutoIt script in which I open a settings dialog from a system tray menu entry. When opening the dialog this way, messages via button clicks are not handled.
On the other hand, when opening the dialog directly (as indicated in the code below, which you can easily test by uncommenting this call and commenting out the call for the system tray entry), then the messages are handled successfully.
Here is my script. When calling SettingsDialog directly (without going via the systray menu), the OK and Cancel buttons work, but otherwise not.
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;; Start program in system tray
SetupSystemTrayEntry()
;; When calling settings dialog directly, messages are handled properly
;;SettingsDialog()
Func SetupSystemTrayEntry()
Opt("TrayMenuMode", 1)
$settingsitem = TrayCreateItem("Settings")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
While 1
Local $traymsg = TrayGetMsg()
Select
Case $traymsg = 0
ContinueLoop
Case $traymsg = $settingsitem
SettingsDialog() ;; Bring up settings dialog
Case $traymsg = $exititem
Exit ;; Exit program
EndSelect
WEnd
EndFunc
Func SettingsDialog()
GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState()
Do
;; These messages are never handled when the dialog is brought up from
;; the system tray menu entry above, but when calling this function
;; directly, it works
Local $settmsg = GUIGetMsg()
Select
Case $settmsg = $ok_button
ExitLoop
Case $settmsg = $cancel_button
ExitLoop
EndSelect
Until $settmsg = $GUI_EVENT_CLOSE
EndFunc

Seems all fine, except you should do something after you left the Do/Until loop.
Func SettingsDialog()
GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState()
Do
;; These messages are never handled when the dialog is brought up from
;; the system tray menu entry above, but when calling this function
;; directly, it works
Local $settmsg = GUIGetMsg()
ConsoleWrite(#HOUR & ":" & #MIN & ":" & #SEC & "," & #MSEC & "msg = " & $settmsg & #CRLF)
Select
Case $settmsg = $ok_button
ExitLoop
Case $settmsg = $cancel_button
ExitLoop
EndSelect
Until $settmsg = $GUI_EVENT_CLOSE
Return GUIDelete()
Endfunc
I added 2 lines, the ConsoleWrite after calling GUIGetMessage and the Return after the loop.
When I run this script the Settings Dialog is properly closed by either clicking 'Ok' or 'Cancel'.

As per solution provided on the AutoIt forum, here is a version of the script that hides and shows the dialog on each usage. There is a big caveat (read the forum thread for details) in that on creation of the dialog, it must be explicitly hidden!
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
; Do not declare Global variables in a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $settings_window_handle, $ok_button, $cancel_button
;; Set up settings dialog
InitSettingsDialog();
;; Start program in system tray
SetupSystemTrayEntry()
Func SetupSystemTrayEntry()
Opt("TrayMenuMode", 1)
$settingsitem = TrayCreateItem("Settings")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
While 1
Switch TrayGetMsg()
Case $settingsitem
ShowSettingsDialog() ;; Bring up settings dialog
Case $exititem
Exit ;; Exit program
EndSwitch
WEnd
EndFunc ;==>SetupSystemTrayEntry
Func InitSettingsDialog()
; Create
$settings_window_handle = GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState(#SW_HIDE, $settings_window_handle)
EndFunc ;==>SettingsDialog
Func ShowSettingsDialog()
GUISetState(#SW_SHOW, $settings_window_handle)
While 1
Switch GUIGetMsg()
Case $ok_button
MsgBox(0, "test", "test")
ExitLoop
Case $cancel_button
ExitLoop
EndSwitch
WEnd
GUISetState(#SW_HIDE, $settings_window_handle)
EndFunc

Related

Is the following codes right? Can I make just one with this two codes?

I'm trying to make a script to start two applications 8:00pm and stop it 8:00am, removing a dir when it stops.
I can't test it right now and I'm new with AutoIt so if someone have any suggestions to my code or know another way to do it (I tried with Task Manager calling batch files but I had some issues). I'll be very happy with your help!
My ideia is to make this script an exe and schedule with Task Manager to start on logon and when 8:00pm it start's the two applications (verifying the OS Arch). I need to make this applications stop 8:00am and I'm thinking in make a second script to do it, but if can be maked with just one script will be better.
It's for Windows machines, x64 or x86.
FIRST SCRIP:
#include <Timers.au3>
#NoTrayIcon
#persistent
loop {
If (A_Hour = 20) and (A_Min = 00) { ; is time 8:00pm?
If #OSArch = "X64" Then
RunWait (C:\ProgramData\...\FirstApp.exe)
Run (C:\ProgramData\...\SecondApp.exe)
Elseif #OSArch = "X86" Then
RunWait (C:\ProgramData\...\FirstApp_x86.exe)
Run (C:\ProgramData\...\SecondApp_x86.exe)
EndIf
}
sleep, 1000 * 60 ; sleep for 60 seconds so only loop once per minute
}
return
SECOND SCRIPT:
#include <Timers.au3>
#NoTrayIcon
#persistent
loop {
if (A_Hour = 08) and (A_Min = 00) { ; is time 8:00am?
Run (#COMSPEC & "taskkill /F /IM FirstApp.exe", #SW_HIDE)
Run (#COMSPEC & "taskkill /F /IM SecondApp.exe", #SW_HIDE)
Run (#COMSPEC & "RMDIR C:\ProgramData\MyDir\ /S /Q", #SW_HIDE)
}
sleep, 1000 * 60 ; sleep for 60 seconds so only loop once per minute
}
return
Try putting your commands inside a function.
#include <Misc.au3> ; needed for _Singleton
_Singleton(#ScriptName, 0) ; allows one one instance of running script
HotKeySet("{ESC}", _close) ; [optional to exit script]
Do
Sleep(20)
;waits for 8 AM
If #HOUR = "08" And #MIN = "00" And #SEC = "00" Then
one()
EndIf
;waits for 8 PM
If #HOUR = "20" And #MIN = "00" And #SEC = "00" Then
two()
EndIf
Until GUIGetMsg() = -3 ; $GUI_EVENT_CLOSE
Func one()
;Add the commmands you want executed at 8AM here
EndFunc ;==>one
Func two()
;Add the commmands you want executed at 8PM here
EndFunc ;==>two
Func _close()
Exit
EndFunc

AutoIt Firefox _FFClick doesn't work on button? (FF.au3)

Using the firefox plugin ("ff-au3") for AutoIt, how do I click a button?
Here is the HTML of the item I'd like to click:
<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
And here is the code snippet to click the button:
;Click the "Log In" button, id is "login-form-submit"
_FFClick("login-form-submit", "id")
At this point, my script is already connected to firefox, already on the page I need, and everything else works (except for this click part!)
Here is the error I get back:
_FFClick ==> No match: $sElement: FFau3.WCD.getElementById('login-form-submit')
Also, this works when I manually run it on the page using a javascript console:
document.getElementById("login-form-submit")
And here is the API for the plugin: http://english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFClick.php
Anyone see anything I'm doing wrong?
Versions:
Firefox 44.0.1
AutoIt v3.3.14.2
FF V0.6.0.1b-15.au3 (Firefox plugin)
MozRepl v.1.1.2
SciTE-Lite v. 3.5.4
Well this didn't get much traffic but I found the solution! Pretty simple... I disconnected from firefox before executing the click!
When using firefox, you first need to open the firefox exe with the "Run" command, then you need to connect to firefox using the "_FFConnect" command. Next you can start clicking elements. Once you're done, disconnect from firefox using the "ProcessClose" command. The problem I was running into was I connected to firefox, then disconnected immediately, then I tried clicking. So, I made sure I disconnected after I did the clicking...
Working solution: myScript.au3 (See the "LogIn" function at the bottom)
#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <EventLog.au3>
#include <FF V0.6.0.1b-15.au3> ;FireFox
OpenLog()
OpenFirefox()
ConnectToFirefox()
LogIn()
; ////////////////////////////////////////////////////
; Configure the Log
; ////////////////////////////////////////////////////
Func OpenLog()
Global $log = FileOpen("K:\Log.txt", 2)
; Check if file opened for reading OK
If $log == -1 Then
FileWrite($log,"[ERROR] Could not open log file." & #CRLF)
MsgBox(0, "Error", "Unable to open log file.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened log file successfully." & #CRLF)
EndIf
EndFunc
; ////////////////////////////////////////////////////
; Open Firefox
; ////////////////////////////////////////////////////
Func OpenFirefox()
;Run Firefox in Maximized
Global $ffPid = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe","",#SW_MAXIMIZE)
; Check if firefox was opened OK
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open firefox." & #CRLF)
MsgBox(0, "Error", "Could not open firefox.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Firefox opened successfully." & #CRLF)
EndIf
;Wait 10 seconds for Firefox to open
$result = WinWait("[CLASS:MozillaWindowClass]","",10)
; Check if file opened for reading OK
If $result == 0 Then
FileWrite($log,"[ERROR] Unable to open firefox class." & #CRLF)
MsgBox(0, "Error", "Unable to open firefox class.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened firefox class successfully." & #CRLF)
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Connect To Firefox
; ////////////////////////////////////////////////////
Func ConnectToFirefox()
; trying to connect to a running FireFox with MozRepl on
If _FFConnect(Default, Default, 3000) Then
FileWrite($log,"[INFO] Connected to Firefox." & #CRLF)
Else
FileWrite($log,"[ERROR] Can't connect to FireFox!" & #CRLF)
MsgBox(64, "", "Can't connect to FireFox!")
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Log into page
; ////////////////////////////////////////////////////
Func LogIn()
;Load Login Page
_FFOpenURL("http://localhost/login.jsp")
Sleep(2000)
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open URL." & #CRLF)
MsgBox(0, "Error", "Could not open URL.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened URL successfully." & #CRLF)
EndIf
Sleep(2000)
;Click the "Log In" button, id is "login-form-submit"
;<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
_FFClick("login-form-submit", "id")
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not click login button." & #CRLF)
MsgBox(0, "Error", "Could not click login button:", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Found and clicked login button successfully." & #CRLF)
EndIf
EndFunc

autoit it possible to use "PixelSearch" and "ControlClick" and "PixelGetColor" on bluestacks

possible to use "PixelSearch" and "ControlClick" and "PixelGetColor" on bluestacks in hind windows
i want to run bot in bluestacks and hind windows but PixelSearch can only use on Windows
i want to use PixelSearch to find colour if true to click on other point and working in hind windows
Local $hwnd, $Cor
$hwnd = WinGetHandle("WindowsForms10.Window.8.app.0.33c0d9d")
While 1
$Cor = PixelSearch(460, 271, 511, 323, 0x9D6F47,$hwnd )
If Not #error Then
ControlClick ( "BlueStacks App Player","","", "left" , 1 , 477, 277 )
sleep(200)
EndIf
$Cor = PixelSearch( 546, 212, 598, 267, 0x431567,$hwnd )
If Not #error Then
ControlClick ( "BlueStacks App Player","","", "left" , 1 , 608, 512 )
sleep(200)
EndIf
WEnd
i try this code it works when bluestacks on fornt but i move screen or hind bluestacks is not works
You can't catch a pixel on an hidden windows. What you can make it's make it appear quickly (
the time to make a capture) an then search forthe pixel in memory.
That's a very quick process. Take a look at this :
http://www.autoitscript.com/forum/topic/126430-advanced-pixel-search-library/

RDP session launch applications

I have opened an RDP session using AutoIt. Here is the code:
$host = "" ; <---- IP
$hGUI = GUICreate("Terminal Serveur", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2")
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ; <--- Username
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = "" ; <--- Password
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()
$oShel = ObjCreate("shell.application")
$oShel_Ctrl = GUICtrlCreateObj($oShel, 64, 44, 800, 600)
GUICtrlSetStyle($oShel_Ctrl , $WS_VISIBLE)
GUISetState(#SW_SHOW, $hGUI)
Send ("#r") ; !!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$oRDP.Disconnect()
Exit
EndSwitch
WEnd
Now, I want to launch an application in the RDP session. I tried " Send(#r) " in order to send the path with a function like SendKeys but this command is execute on my computer and not on the remote computer.
How can I do please?
Send alt + home. This open the windows search in the rdp session, which you can then send it text e.g. send("notepad")
send({enter})
Update:
A much simpler alternative:
Change the Remote Desktop Connection Settings (not in the control
code, but in the usual windows shorcut. But it seems that could be done in the AutoIt code with the keyboardhook setting keyboardhook setting ) .
Look for the Options button, in the window when launching remote desktop.
On the Local Resources Tab select Windows key combinations are applied in full-screen mode only.
Change this line in your code:
$oRDP.Fullscreen = True
Include a pause to ensure the control has been loaded
Sleep(5000)
Send ("#r")
Previous answer:
Let my suggest a workaround not very 'elegant' but should work (tested ok):
In the remote desktop make a shorcut to the Windows Virtual Keyword (On-Screen Keyboard or OSK)
Find the position of the shorcut icon
In your code send a double click at this position to start the on-screen keyboard
Then send clicks to the positions of the desired keys
Something like this:
Sleep(5000)
MouseClick("left",512,191,2) ;start virtual keyword
Sleep(1000)
MouseClick("left",553,807,1) ;click
Sleep(100)
MouseClick("left",633,740,1)
Sleep(1000)
Send("notepad")
Sleep(1000)
Send("{ENTER}")
(Aside note: For any executable with a shortcut on the remote desktop simply send double click, without the need of the virtual keyboard)

Autoit Unable to open the script file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am creating a basic installer in autoit. After compiling the script, I got the error Unable to open the script file when trying to run it.
The Script:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <resources.au3>
$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")
If $msgbox1 = 6 Then
GUICreate("Minecraft Server Launcher Installer", 373, 325)
GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
GUICtrlCreateEdit(_ResourceGetAsString("Licence"), 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & #CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
$YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
$NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $YES
Choose_Loc()
Case $NO
Exit
EndSwitch
WEnd
EndIf
Func Choose_Loc()
GUIDelete()
GUICreate("Minecraft Server Launcher Installer", 363, 108)
GUICtrlCreateLabel("Choose Install Location", 10, 5)
$INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
$BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
$CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
$OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $CANCEL
Exit
Case $OK
Install($INPUT)
Case $BROWSE
$FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
EndSwitch
WEnd
EndFunc ;==>Choose_Loc
Func Install($INPUT)
_ResourceSaveToFile(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", "Launcher", $RT_RCDATA, 0, 1)
FileCreateShortcut(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", #DesktopDir & "\Bungee Minecraft Server Launcher.ink")
GUIDelete()
If Not #error Then
MsgBox(36, "Finished", "Installation completed with no errors. Please enjoy your new software.")
Else
MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
EndIf
Exit
EndFunc ;==>Install
I know that it's this line that creates the error:
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence
But I don't know why or how to fix it. I had the same problem with:
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher
I know that it's the Res_Add line because if I remove that line, the error will disappear.
I stopped using the res file stuff, and switched to FileInstall() :
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe",#TEMPDIR & "\Bungee Minecraft Server Launcher.exe")
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt",#TEMPDIR & "\Licence.txt")
Then you just use the file. Also, your paths are different:
Autoit\{BUNGEE MINECRAFT SERVER LAUNCHER.EXE}
Autoit\Bungee Server Launcher\{LICENCE.TXT}
Open up a command prompt and check the full path :
cd C:\Users\Kristian\SkyDrive\Autoit & dir licence.txt /b /s
Another solution would be to make the text file a variable. Open the file in SciTE, replace the regular expression ^(.*)$ by "$1" & #CRLF &_, then copy and paste it into the script.
Here is the code with FileInstall() and a couple fixes. I tested with different paths, and it worked. Functions should be self-contained, so I made them mostly internal. Ideally, you'd have them do a Return SetError() and put the MsgBox() outside the function call.
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
; Target path of temp files - you should add code to delete these when done
$LAUNCHPATH = #TempDir & "\BMSLauncher.exe"
$LICENCEPATH = #TempDir & "\BMSLicence.txt"
; Check if the install files exist, and if not, output to console
$EXIST1 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe")
$EXIST2 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt")
If Not $EXIST1 Or Not $EXIST2 Then
ConsoleWrite("ERROR! FILE(S) NOT FOUND!" & #CRLF)
If Not $EXIST1 Then ConsoleWrite("LAUNCHER FILE NOT FOUND!" & #CRLF)
If Not $EXIST2 Then ConsoleWrite("LICENCE FILE NOT FOUND!" & #CRLF)
EndIf
; Copy files to destination
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe", $LAUNCHPATH, 1)
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt", $LICENCEPATH, 1)
; Read licence file to variable
$LICENCE = FileRead($LICENCEPATH)
$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")
If $msgbox1 = 6 Then
$EULAGUI = GUICreate("Minecraft Server Launcher Installer", 373, 325)
GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
GUICtrlCreateEdit($LICENCE, 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & #CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
$YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
$NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $NO
Exit
Case $YES
GUIDelete($EULAGUI)
Choose_Loc()
EndSwitch
WEnd
EndIf
Func Choose_Loc()
Local $LOCGUI = GUICreate("Minecraft Server Launcher Installer", 363, 108)
GUICtrlCreateLabel("Choose Install Location", 10, 5)
$INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
$BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
$CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
$OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
GUISetState(#SW_SHOW)
While 1
; you could make the switch guigetmsg() without $msg, idk what's best practice here
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $CANCEL
Exit
Case $OK
Local $INSTALLPATH = GUICtrlRead($INPUT)
If FileExists($INSTALLPATH) Then
GUIDelete($LOCGUI)
Install($LAUNCHPATH, $INSTALLPATH)
EndIf
Case $BROWSE
$FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
EndSwitch
WEnd
EndFunc ;==>Choose_Loc
Func Install($FPATH, $IPATH)
Local $ERROR
; you should check for a trailing slash on the $IPATH input
$IPATH &= "\Bungee Minecraft Server Launcher.exe"
FileCopy($FPATH, $IPATH)
$ERROR = #error
FileCreateShortcut($IPATH, #DesktopDir & "\Bungee Minecraft Server Launcher.ink")
If Not #error And Not $ERROR Then
MsgBox(64, "Finished", "Installation completed with no errors. Please enjoy your new software.")
Else
MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
EndIf
Exit
EndFunc ;==>Install
Make sure the file is in the same dir as the script and Try:
#AutoIt3Wrapper_Res_File_Add=Licence.txt, rt_rcdata, Licence
If you still have problems, try to turn off UPX.

Resources