Jump to content

Using .au3 as config file


corgano
 Share

Recommended Posts

Is there any way to use a .au3 file as a config file?

From what I understand, when you #include a file, it gets added to the script and they are both compiled together. Is it possible to compile only the script and then "include" the file at runtime? So that you would have "Script.exe" and a "Config.au3" and when you run Script.au3, it would add everything in config.au3 and then run?

Or is this a horriable idea for some reason I'm not aware of yet

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

You can do that, but I do not see any benefit from doing so. in the #include file, you will have variables to hold your data and when you run your main script, it accesses the #include file for the data. But that's no different than just putting your variables in your script.

Edit: re-reading what you said, I do not think you can compile the script if the #include file is missing. What you want would best using an INI file.

Edited by abberration
Link to comment
Share on other sites

If you are not going to compile the script, then you can use an .AU3 for a config file, no problem.  But, once you compile the script, that .AU3 file has already been read in and compiled.  It will not be read again at runtime.

It would be simpler to use an .INI file, and read in the values at the beginning of your script.  I usually set default values in the script first, in case the INI file is not there, or is missing values.  You can't trust users to get it right every time.  :)

You don't have to use the .INI extension if you do not like it.  I sometimes change it to .CNF.  IniRead, IniWrite, etc... will still work with it.

Link to comment
Share on other sites

I know that's what #include does when you compile, I'm just wondering if there's a way to do the same thing it does when the script is compiled as when it's not compiled

 

The advantage is it would be easier to declare simpler things like dictionary objects in a .au3 file than in an INI. I asked mostly out of curiosity.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Maybe I do not understand what you're asking, but maybe AutoIt3ExecuteScript is it.

I think the OP is wanting to let the user of his compiled script set values that the script will be able to use for config purposes.  I don't think that AutoIt3ExecuteScript will work in this case, since the script it runs will have its own variable space that is not shared with the calling script.

EDIT:

I missed seeing post #4.  Now I am confused as to what is being asked for.

Edited by willichan
Link to comment
Share on other sites

I want a compiled exe script that has something like an include file, to the effect that when you run the exe, it will load and run the "somthing like include" file, and then run itself while maintaining all the variables declared in the other file

compiled.exe

settings.au3

start compiled.exe, it will run everything in settings.au3 and then continue executing while keeping all variables and functions declared in settings.au3

 

not sure how else to explain it

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Perhaps it's possible reading the AU3 file and executing functions (Execute())

Depends on what functions they are, multiline UDF's will probably not work.

I'm sure you have some great reason for thinking such a thing would be good, but I'm struggling to think of a scenario where it would be useful, which is where inspiration comes from.

Best of luck.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

As far as including a file, there is FileInstall.

There are also some dynamic methods that trancexx (if I remember right) and maybe one or two others have created, that a search would likely reveal.

At the end of the day though, unless you are intent on recompiling on the fly, then what you are proposing has limited benefit over something like an ini file.

Conceivably, you could get your script to read in the content of an .au3 file and act according to that content, but that could be so fraught with issues ... and could still be better done, to my mind, with something like an ini, xml, etc approach.

I'm presuming, that you don't mind if the extra file is external, outside your compiled exe?

One way to do what you want, is to write a small script, that uses AutoIt.exe with your main script and this other .au3 file, to run each time. This means you are essentially just running a script, with an onboard portable version of AutoIt.exe in the package. This last, would only be needed if the host system did not have an AutoIt install (or correct one).

So basically, you would have a file scenario like the following.

Simple compiled controlling script, that has the following using FileInstall.

[1] Main script (.au3) with appropraite Include line for the following

[2] Extra script (.au3) which is mentioned as an Include in the main script above.

[3] (If needed) AutoIt.exe (portable version with all needed dependencies).

When your simple compiled script runs, it extracts the FileInstall files to it's parent directory and then runs the main script, using a version of AutoIt (portable if needed). Obviously you can make changes to the extra script referenced by Include, but they would only be utilized if you have the right code in the main script ... though being an .au3 too, it could also be modified.

Hope that's as clear as water .... that's clear and not muddy!

P.S. Of course, you could include your simple script and the others as FileInstall files in another Install script, so that extraction only occurs once ... that's what I'd do.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • 3 years later...

Welp, Years later and looking for a solution to a problem I forgot i asked long ago, and ran into myself in the search results. This time I'm trying to make my compiled script load "plugins" written as au3 files in a plugin folder, just like as if they were #included. New script, old problems :P

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Still won't work. Compiled scripts only read in an include when it's compiled. You could use a script compiled to an .a3x file instead and execute it, but it would have to have it's name hard coded into the script and the .a3x file would have to be recompiled itself everytime you change something in it.

As stated above, your best bet for something like this is an INI file or even just a text file that gets read by your script, but you can't include code in them unless you're planning on using the Execute command.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Same problems alternative solutions

https://www.autoitscript.com/forum/topic/188158-net-common-language-runtime-clr-framework/

dynamic code from string

 https://www.autoitscript.com/forum/topic/187334-using-net-libary-with-autoit-possible/?do=findComment&comment=1356911

and as with AutoItX you have your .NET assembly you can combine the things.

Looks to heavy for your question but maybe it is one of the alternatives to invistigate

Link to comment
Share on other sites

Well nice to see some ideas come up

At Execute(), if I could have the script run the whole file as if it was a section of itself that'd work. All the "plugins" do is have some variables and Func 's in them, if I could just run the file and define all the variables and func's so the rest of the script could use them, that'd be great. All my attempts of just execute( fileread( "filename.au3" ) ) have failed though. I get the impression this is far from simple.

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Here is my understanding of what you want.

  • be able to call an external script from your compiled "main" script in a plug-in like fashion.
    • pass data/variables to the "plug-in"
    • execute custom code in the "plug-in"
    • return data/variables from the "plug-in" to the "main" script

Limitations you will need to keep in mind

  • the "main" script will not be able to access functions in the "plug-in" directly
  • the "plug-in" will not have access to functions in the "main" script at all
  • neither "main" nor "plug-in" scripts will have direct access to each others data/variables

Given these limitations, what you want is not a simple thing, but is not impossible.  Here is one possible solution.

--------

  1. from the "main" script, write out data/variables the the "plug-in" will need to a temporary (ini) file
  2. shell out to the .au3/.aux "plug-in", passing the temporary file in the command line as a parameter
    • If you are calling just a particular function of the "plug-in", pass the desired function, as an additional command line parameter
  3. from the "plug-in", read in the data from the temp file, and do its thing
  4. when the "plug-in" is done doing its thing, write any return data back to the temporary file for "main" to be able to see it.
  5. from the "main" script, read back in the temp file and update variables accordingly
  6. delete the temp file (don't want to junk the PC up with old temp files)

--------

I personally would not do this, because it is fraught with security issues.  Do not do this if any data involved is of a personal or confidential nature.  If, however, you really need to do it, this should accomplish the task.

 

Edited by willichan
typo
Link to comment
Share on other sites

Using command line parameters, an ini file or the registry is just too complicated, I agree. There is however an easy solution: Just write an interpreter for AutoIt in the language AutoIt itself. Compile this interpreter to an exe file, and include your actual program in a string (source code) and parse that string when you start the exe file. Your program can use #include to load any au3 file at runtime, and use the variables defined there. Just to it!

 

Link to comment
Share on other sites

At this point it has become clear this is not possible / requires too much ballache to be practical. Thanks for all the replies, surely some interesting ideas, but I've given up on this particular idea for now.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

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

×
×
  • Create New...