Jump to content
corgano

Using .au3 as config file

Recommended Posts

corgano

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

Share this post


Link to post
Share on other sites
abberration

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

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites
willichan

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.

Share this post


Link to post
Share on other sites
corgano

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

Share this post


Link to post
Share on other sites
willichan

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

Share this post


Link to post
Share on other sites
corgano

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

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
TheSaint

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites
corgano

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
junkew

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

Share this post


Link to post
Share on other sites
corgano

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

Share this post


Link to post
Share on other sites
willichan

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

Share this post


Link to post
Share on other sites
MazeM

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!

 

Share this post


Link to post
Share on other sites
corgano

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

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

  • Similar Content

    • ur
      By ur
      The below functions are to write data to a configuration or property file and also read them back.
      BuildLocation:C:\Build BuildExe : setup.exe Release:r9.7 Silent:No InstallPath:default Compare :No MartUpgrade :Yes Bit:64 ERwinUpgrade:No License_File:150416-1952 Navigator (ca.com).lic You can change the character from ":" to "=" or whatever based on your requirement and update the code also accordingly.
      Property.au3
    • ur
      By ur
      Hi,
       
      I have a property file format configuration file for our project.
      The sample file is as below.
      BuildLocation:C:\Build BuildExe:erwin Data Modeler r9.7 (64-bit)_2378.exe Release:r9.64.02 Silent:No InstallPath:default Compare :No MartUpgrade :Yes Bit:64 ERwinUpgrade:No License_File:150416-1952 Navigator (ca.com).lic To read this file, I am using below code.
      Func readConfig($sFilePath,$intStartCode) ;Usage: MsgBox(0,"Silent",readConfig(@ScriptDir&"\Config.txt","Silbent")) ;$sReplaceText = "Mani Prakash" ;$sFilePath = "C:\Users\KIRUD01\Desktop\Config.txt" ;$intStartCode = "BuildExe" $arrRetArray = "" $s = _FileReadToArray($sFilePath, $arrRetArray);Reading text file and saving it to array $s will show status of reading file.. For $i = 1 To UBound($arrRetArray)-1 $line = $arrRetArray[$i];retrieves taskengine text line by line If StringInStr($line, $intStartCode) Then ConsoleWrite ("Starting point "& $line & @CRLF) return StringStripWS(StringSplit($line,":")[2],$STR_STRIPLEADING + $STR_STRIPTRAILING ) EndIf if $i = UBound($arrRetArray)-1 then return "Not Found" Next EndFunc The above code is working to read the particular key value.
      But problem is , if I try to read the key "Bit" it is giving the value of key "BuildExe" as the line contains the word "bit"..
      Can you suggest how to do this. 
       
      If possible I need to fix writeConfig also.
       
      Func writeConfig($sFilePath,$intStartCode,$sReplaceText) ;$sReplaceText = "Mani Prakash" ;$sFilePath = "C:\Users\KIRUD01\Desktop\Config.txt" ;$intStartCode = "BuildExe" $arrRetArray = "" $s = _FileReadToArray($sFilePath, $arrRetArray);Reading text file and saving it to array $s will show status of reading file.. $intStartingPointFound = 0 For $i = 1 To UBound($arrRetArray)-1 $line = $arrRetArray[$i];retrieves taskengine text line by line If StringInStr($line, $intStartCode) Then $intStartingPointFound = 1;if found the starting point of the module to copy then set this variable to 1 ConsoleWrite ("Starting point " & @CRLF) $arrRetArray[$i] = $intStartCode & ": " & $sReplaceText ExitLoop EndIf if $i = UBound($arrRetArray)-1 then ConsoleWrite("Not Found" & @CRLF) Next _FileWriteFromArray ($sFilePath, $arrRetArray,1) EndFunc  
    • ur
      By ur
      I have a custom configuration file which has key-value pairs as in below format.
      BuildLocation:C:\Build BuildExe:setup.exe Release:r9.64.02 Silent:No InstallPath:default Compare :No MartUpgrade :Yes Bit:64 ERwinUpgrade:No I need to change the value of "BuildExe" using my program.
      Is there any inbuilt function already available for these kind of files?.
      Can any one help me how to do this.
    • Cormin
      By Cormin
      I've never worked with an array or dropdown menu before and I can't seem to wrap it around my head this morning.  Maybe I just need more coffee but I'm trying to populate a GUI dropdown menu with section names of a .ini file.  Here is what I have for this part but I don't know where to go from here.  The msgbox thing was only testing it but I kinda got stuck here.
       
      local $aSectionnames = IniReadSectionNames(@DesktopDir & "\Scripts\BatteryConfig.ini") if Not @error Then For $i = 1 to $aSectionnames[0] MsgBox($MB_SYSTEMMODAL, "Test", $aSectionnames[$i]) Next EndIf  
      Here is my very basic dropdown menu I want to populate
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 413, 213, 192, 124) $Combo1 = GUICtrlCreateCombo("Combo1", 80, 24, 241, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Button1 = GUICtrlCreateButton("Button1", 152, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
       
      Thanks!
    • Caster
      By Caster
      I am currently working on a (small) project, which will set my pc screen blank for x seconds and then turn it back on. The code looks like this now (I've copied the blackscreen func and put some other variables in):
      func BlackFor($time) Global $untilback = $time EndFunc BlackFor(5000); Sets how long the screen should be black, in milliseconds. func screenFlicker() Opt("WinTitleMatchMode", 4) $WM_SYSCommand = 274 $SC_MonitorPower = 61808 $Power_On = -1 $Power_Off = 2 $X = 1 $HWND = WinGetHandle("classname=Progman") DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", $Power_Off) Sleep($untilback) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", $Power_On) endFunc screenFlicker()
      But, when I start a project and it works, I want to make it even better. So I thought about a GUI which sets the milliseconds to a config file. I understand the GUI part, but I need a solution of a config file. I saw a topic some months ago with a config script saver - which I can't find anymore. I've searched on Google, AutoIt forums.. can't find that excact one. It had functions like ConfgWrite and ConfgRead I think. I've looked into the AutoIt config systems, but I really want a config to be saved somewhere on a pc - easy to edit even without the editor I'll make for the script.

      The reason I want this screen-flicker, is that it might come good in the future :3 Even though I know that there are lots of these already...

      -CasterAnd
×