SxyfrG Posted February 3, 2008 Posted February 3, 2008 I just wanted to create a smaller version of an executable i wrote in AutoIT3. If anyone can convert the following into v2 syntax, I'd be very grateful #NoTrayIcon Sleep ( 10 ) FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" ) If @Error=1 Then MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" ) Exit EndIf If ProcessExists ( "GameLauncherTRAY.exe" ) Then Sleep ( 10 ) Run ( @ScriptDir & "\GameLauncherTRAY.exe" ) Else Run ( @ScriptDir & "\GameLauncherTRAY.exe" ) EndIf Exit My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website
Valik Posted February 3, 2008 Posted February 3, 2008 I just wanted to create a smaller version of an executable i wrote in AutoIT3. If anyone can convert the following into v2 syntax, I'd be very grateful #NoTrayIcon Sleep ( 10 ) FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" ) If @Error=1 Then MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" ) Exit EndIf If ProcessExists ( "GameLauncherTRAY.exe" ) Then Sleep ( 10 ) Run ( @ScriptDir & "\GameLauncherTRAY.exe" ) Else Run ( @ScriptDir & "\GameLauncherTRAY.exe" ) EndIf ExitHow about converting it into a non-retarded script first? Let's start at the top. You have a sleep so small it does no good, and it's the first line of the script. Why?You want to know if a file exists but you check it's attributes instead of using FileExists(). Why?The If ProcessExists() block is really bad. First, you have duplicate code. You don't need 2 run statements, you only need 1. The only thing you want to do if the process exists is sleep a little. That brings me to the second point, the sleep statement is so short it does nothing. The If structure can be removed and just use a Run() statement.You used Exit as the line line of the script. Why? What else can the script do?You have about a 4-line script you've inflated to 14. Maybe if you cut it down to the 3 or 4 lines it should be, you can convert it yourself?
SxyfrG Posted February 3, 2008 Author Posted February 3, 2008 (edited) I'm sorry if i'm very new to AutoIT Valik, but calling my script retarded, even though it serves its purpose very well, isn't the best way to introduce someone to the forum ... For the sake of receiving some sort of response, i cut the script down for you ... #NoTrayIcon FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" ) If @Error=1 Then MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" ) Exit ElseIf ProcessExists ( "GameLauncherTRAY.exe" ) Then Sleep ( 10 ) EndIf Run ( @ScriptDir & "\GameLauncherTRAY.exe" ) The sleep is there to give the program time to terminate Valik, i tested the script multiple times without the sleep and sometimes GameLauncherTRAY won't run because it's already running (i have a statement at the start of the GameLauncherTRAY script which detects if it's running and if it is, it terminates with a MsgBox saying it's already running). I've also converted some of it into v2 syntax, but i'm just wondering ... how do i use the A_SCRIPTDIR special variable in the run statement? Is it the same as @ScriptDir? e.g. Run ( @ScriptDir & "\MyFile.exe" ) Edited February 3, 2008 by SxyfrG My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website
Valik Posted February 3, 2008 Posted February 3, 2008 You only listened to half of what I said. You changed the code around, it's not really any better. And you're trying to wait on a process to close with a sleep time so small that it's pure luck that it works. #NoTrayIcon Local Const $sExe = "GameLauncherTRAY.exe" Local Const $sFile = @ScriptDir & "\" & $sExe If FileExists($sFile) Then If ProcessExists($Exe) Then ProcessWaitClose($sExe) Run($sFile) Else MsgBox ( 48 , "Error!" , $sExe & " not found! Please make sure you have not renamed it. If you have, rename it back to '" & $sExe & "'" ) EndIf It's ironic to me that you want a small executable but aren't concerned about code that takes a round-about way to it's destination.
SxyfrG Posted February 3, 2008 Author Posted February 3, 2008 I see what you're saying, and i thank you for the supplied code, but i still haven't figured out how to use the A_SCRIPTDIR special variable for v2 syntax :S My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website
Zedna Posted March 16, 2008 Posted March 16, 2008 (edited) Here is base syntax (not tested): HideAutoItWin, on HideAutoItDebug, on IfNotExist, %A_SCRIPTDIR%\\GameLauncherTRAY.exe, Goto, Error1 ;If ProcessExists($Exe) Then ProcessWaitClose($sExe) ;Run, GameLauncherTRAY.exe Run, %A_SCRIPTDIR%\\GameLauncherTRAY.exe Exit Error1: MsgBox, 48, Error!, GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to GameLauncherTRAY.exe Exit There is no alternative for ProcessExists as far as I know. You can use only similar IfWinNotExist. Edited March 16, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Recommended Posts