Sign in to follow this  
Followers 0
puttwill

Help with a conf file generator

8 posts in this topic

I am looking to use AutoIT to make a conf file generator for equipment at work. These are standard configs where currently I use notepad's find and replace to replace variables like IP address, port number, and customer name. I want to have standalone EXE's where the script asks for the information, and once it's all typed in, clicking submit gives me a screen where I can copy the text. I know this is a simple script but my ability to write a script from scratch is limited. If I have an example and I can usually poke it and change it until it’s what I want. I went through all the examples that it came with and that were posted here but found nothing that asked the user for input, and then displayed it back with inside other text to the user. Does anyone know of such an example I can work from? Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Can you provide an example of the config file format? There are several ways you can do it, and that will (in part) determine the route you go. Without seeing an example, I would say at a high level you could do something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Test", 300, 150)
$iplbl = GUICtrlCreateLabel("IP address", 30, 10, 60, 20)
$namelbl = GUICtrlCreateLabel("ComputerName", 115, 10, 80, 20)
$domainlbl = GUICtrlCreateLabel("Domain", 220, 10, 100, 20)

$ip = GUICtrlCreateInput("", 20, 30, 80, 30)
$name = GUICtrlCreateInput("", 110, 30, 80, 30)
$domain = GUICtrlCreateInput("", 200, 30, 80, 30)

$go = GUICtrlCreateButton("Save to config file", 10, 80, 100, 30)
$exit = GUICtrlCreateButton("Exit", 210, 80, 80, 30)

GUISetState(@SW_SHOW)

    While 1
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE, $exit
                    ExitLoop
                Case $go
                    ;Copy input values to config file
            EndSwitch
    WEnd

GUIDelete()
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

We got really busy after I posted about this. We have finally slowed down enough that I can work on this. This is almost what I'm looking for but I want it to display on the screen not save to a file. I tried to do this my self but I'm not finding a way to display variables inside of a block of text on the screen like I could with Automate. I would hate to just put tons labels in. Seems like there should be a way to have it display a block of text. Even trying to get it to display a varible in a lable though response with "6" no matter what input I give it. I'm not sure what I'm doing wrong. Could some one take a look at what I've come up with so far and give me some pointers? Thanks.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("input", 300, 150)
GUICtrlCreateLabel("IP address", 30, 10, 60, 20)
GUICtrlCreateLabel("ComputerName", 115, 10, 80, 20)
GUICtrlCreateLabel("Domain", 220, 10, 100, 20)

$ip = GUICtrlCreateInput("", 20, 30, 80, 30)
$name = GUICtrlCreateInput("", 110, 30, 80, 30)
$domain = GUICtrlCreateInput("", 200, 30, 80, 30)

$go = GUICtrlCreateButton("Generate", 10, 80, 100, 30)
$exit = GUICtrlCreateButton("Exit", 210, 80, 80, 30)

GUISetState(@SW_SHOW)

    While 1
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE, $exit
                    ExitLoop
                 Case $go
                    GUIDelete()
                    GUICreate("output", 300, 150)
                    GUICtrlCreateLabel($ip, 30, 10, 60, 20)
                    GUISetState(@SW_SHOW)
            EndSwitch
    WEnd

GUIDelete()

Share this post


Link to post
Share on other sites

You need to read the contents of the controls, using GUICtrlRead($ip) for example, the variable $ip only holds the AutoIt control ID for the control.


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

I figured out a way to do this with autoit. I'm sure folks will have comments about how i did it, i just hacked together a bunch of examples and it works for me. Posting in case future seekers find it useful. I had to use txt file as you can't copy out of a message box.

FileDelete ( "test.txt" )
$file = FileOpen("test.txt", 1)

$sIPadd = InputBox("IP Address", "Please type in the IP Address")

If $file = -1 Then
  MsgBox(0, "Error", "Unable to open file.")
Else
  FileWrite($file, "Here is the config" & @CRLF)
  FileWrite($file, "ip address is " & $sIPadd & @CRLF) ; The CRLF at the end is a line break
  FileWrite($file, "that's it")
  FileClose($file)
EndIf
ShellExecute ( "test.txt" )

Share this post


Link to post
Share on other sites

I found the missing part of JLogan3o13's code. Again, this is for any future folks finding this page. You need to use GUICtrlRead to pull the data from the gui variable to a usable variable. Here's a the usage... $iP = GUICtrlRead($iplbl). Put it before GUIDelete() and now you can use $ip as you want.

Share this post


Link to post
Share on other sites

That's what I said in post #4, 5 months ago. All you had to do is read my reply and you would have known this without going about it the hard way.

1 person likes this

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

#8 ·  Posted (edited)

...was the nicest reply ever (at least of the few that went through my head).

If I was the one inventing the warning point, this would be case #1 of how to earn it.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
Sign in to follow this  
Followers 0