Jump to content

Self compile an .exe of a .au3 file from within the .au3 file.


tantrim
 Share

Go to solution Solved by tantrim,

Recommended Posts

I receive the error Error copying source to destination file when I try and run the exe I have created with the code below.

Is it possible to self compile a .au3 file into a .exe from within the same file via command line  with /in and /out?

This is the code I'm currently using. The file is named test.au3 and I'm trying to compile the same file, test.au3

local $cmdCommand = "Aut2exe.exe /in " & @ScriptDir & "\test.au3 /out " & @ScriptDir & "\tt.exe"; /icon " & @ScriptDir & "\robo.ico"; /x64"
ConsoleWrite($cmdCommand & @CRLF)
RunWait(@ComSpec & " /k " & $cmdCommand, "", @SW_SHOW)


I found wrapit from @Melba23. Is this what it requires to do such a task? I'm asking because it seems like it's quite involved and maybe I should just avoid trying to self compile an exe lol.

My goal is to put the created .exe within my windows startup folder so that my program launches on startup. I want to also automatically update that created .exe in the startup folder whenever I run my .au3 file manually when working on it. If there is a simpler way to do this please let me know.

Edited by tantrim
Link to comment
Share on other sites

  • tantrim changed the title to Self compile an .exe of a .au3 file from within the .au3 file.
  • Developers

Try putting the source and target in double quotes to be able to handle spaces in them:

local $cmdCommand = 'Aut2exe.exe /in "' & @ScriptDir & '\test.au3" /out "' & @ScriptDir & '\tt.exe"'

I assume aut2exe.exe is in the path or current directory.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

10 hours ago, Jos said:

Try putting the source and target in double quotes to be able to handle spaces in them:

local $cmdCommand = 'Aut2exe.exe /in "' & @ScriptDir & '\test.au3" /out "' & @ScriptDir & '\tt.exe"'

I assume aut2exe.exe is in the path or current directory.

aut2exe.exe is in the environment path and working in cmd from any directory.

This appears to make no difference. I also have no spaces in the @ScriptDir path

2 hours ago, Zedna said:

Just note:

Compiled EXE file can't be used (without external Aut2Exe.exe) for compiling another scripts, it can be used for other scripts only as runtime (like/instead AutoIt3.exe).

I'm not sure I understand what you're saying. I'm able to take the output from line 2 of my code above and paste that manually into cmd which creates a working .exe. The issue I seem to have is that I can't create a working .exe when that command line is kicked off by my script. I think it's because the .au3 is in use so the compiler can't copy it.

The script above can create a working .exe of another .au3 file without issue only IF I start that .exe after my current .au3 file is done running and not currently executing.

Edited by tantrim
Link to comment
Share on other sites

  • Developers

Just checked and this version works for me: 

local $cmdCommand = '""C:\Program Files (x86)\AutoIt3\aut2exe\Aut2exe.exe" /in "' & @ScriptDir & '\test.au3" /out "' & @ScriptDir & '\tt.exe""'

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

On 12/11/2022 at 2:27 PM, Jos said:

Just checked and this version works for me: 

local $cmdCommand = '""C:\Program Files (x86)\AutoIt3\aut2exe\Aut2exe.exe" /in "' & @ScriptDir & '\test.au3" /out "' & @ScriptDir & '\tt.exe""'

 

When I run the command line it still throws an error for me.

error1.thumb.gif.70d9291d67569950a1c8967caf66144e.gif

However, I did find a solution.

Before I share, I want to ask a question. How does @ScriptDir function?

Lets say I have a script C:\Users\Coding\Dropbox\Coding\Software\DesktopAutomation\WindowsShortcutstest.au3 that contains @ScriptDir but gets compiled with Aut2exe.exe and /out to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\tt.exe.

does that @ScriptDir change to the ProgramData path when that exe C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\tt.exe is ran? From my tests that appears to be the case.

Link to comment
Share on other sites

  • Developers

Did you exclude your script and target directory from an AntiVirus you are running....  and please don't post these flashing running gifs as it is impossible to read what it says.!

Just post the relevant info likeyour code, errors etc!

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

The solution

It's a very round about way of trying to accomplish my quote below

On 12/11/2022 at 1:59 AM, tantrim said:

My goal is to put the created .exe within my windows startup folder so that my program launches on startup. I want to also automatically update that created .exe in the startup folder whenever I run my .au3 file manually when working on it.

So what I did was manually create WindowsShortcutsStartupLauncher.au3 file using FileWrite and then immediately compile that file into my @StartupCommonDir. This function lives in my main script and compiles automatically into my common startup directory whenever ran. The purpose of this is so I don't have to manually place the WindowsShortcutsStartupLauncher.exe in the startup directory of every new PC I run this on.

;WindowsShortcuts.au3

Func CreateStartupEXE()
    ;This creates the StartupLauncher.au3 with a static path for the current computer.
    ;After creating StartupLauncher.au3, it compiles it and places it in the Shared Startup folder - C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
    ;This exe will recompile the latest code on startup and then launch that code so you always have the latest on every startup.
    Local $hFileOpen = FileOpen("WindowsShortcutsStartupLauncher.au3", $FO_OVERWRITE)
    local $cmdCommand = "Aut2exe.exe /in " & SurroundWithQuotes(@ScriptDir & "\WindowsShortcuts.au3") & " /out " & SurroundWithQuotes(@ScriptDir & "\WindowsShortcuts.exe") & " /icon " & SurroundWithQuotes(@ScriptDir & "\smiley.ico"); /x64"
    FileWriteLine($hFileOpen, "local $cmdCommand = '" & $cmdCommand & "'")
    FileWriteLine($hFileOpen, 'ConsoleWrite($cmdCommand & @CRLF)')
    FileWriteLine($hFileOpen, 'RunWait(@ComSpec & " /c " & $cmdCommand, "", @SW_HIDE)')
    FileWriteLine($hFileOpen, 'Sleep(100)')
    FileWriteLine($hFileOpen, 'Run(' & SurroundWithQuotes(@ScriptDir & "\WindowsShortcuts.exe") & ')')
    Sleep(100)
    ;compile WindowsShortcutsStartupLauncher.au3 and place in common startup directory
    $cmdCommand = "Aut2exe.exe /in " & SurroundWithQuotes(@ScriptDir & "\WindowsShortcutsStartupLauncher.au3") & " /out " & SurroundWithQuotes(@StartupCommonDir & "\WindowsShortcutsStartupLauncher.exe") & " /icon " & SurroundWithQuotes(@ScriptDir & "\smiley.ico"); /x64"
    RunWait(@ComSpec & " /c " & $cmdCommand, "", @SW_HIDE)
EndFunc

this then creates this file below with static paths.

;WindowsShortcutsStartupLauncher.au3

local $cmdCommand = 'Aut2exe.exe /in "C:\Users\Coding\Dropbox\Coding\Software\DesktopAutomation\WindowsShortcuts\WindowsShortcuts.au3" /out "C:\Users\Coding\Dropbox\Coding\Software\DesktopAutomation\WindowsShortcuts\WindowsShortcuts.exe" /icon "C:\Users\Coding\Dropbox\Coding\Software\DesktopAutomation\WindowsShortcuts\smiley.ico"'
ConsoleWrite($cmdCommand & @CRLF)
RunWait(@ComSpec & " /c " & $cmdCommand, "", @SW_HIDE)
Sleep(100)
Run("C:\Users\Coding\Dropbox\Coding\Software\DesktopAutomation\WindowsShortcuts\WindowsShortcuts.exe")

and now on startup, WindowsShortcutsStartupLauncher.exe in my startup folder will run which recompiles WindowsShortcuts.au3 and then runs that new .exe with my latest code.

Edited by tantrim
Link to comment
Share on other sites

11 minutes ago, Jos said:

Did you exclude your script and target directory from an AntiVirus you are running....  and please don't post these flashing running gifs as it is impossible to read what it says.!

Just post the relevant info likeyour code, errors etc!

In Windows Security I've excluded the paths, .au3, and .exe. The Error: Error copying source to destination file still occurs.

I don't run any antivirus to my knowledge and have also attempted turning off Real-Time protection in Windows Security. I've done all of these things at the same time.

I've also killed all dropbox processes as well.

Edited by tantrim
Link to comment
Share on other sites

I'd recommend using AutoitWrapper.au3 included in SciTE4AutoIt for Continuous Integration like you're wanting do. I remember trying to do similar with Au32exe and having issues that using AutoItWrapper.au3 resolved. Plus you can just copy the command straight out of SciTE.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

On 12/13/2022 at 3:08 PM, rcmaehl said:

I'd recommend using AutoitWrapper.au3 included in SciTE4AutoIt for Continuous Integration like you're wanting do. I remember trying to do similar with Au32exe and having issues that using AutoItWrapper.au3 resolved. Plus you can just copy the command straight out of SciTE.

I looked into this and can't find any information on AutoitWrapper.au3 implementation. Do you have any links you can share?

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...