Computing.Net > Forums > Programming > Batch file to create ini file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to create ini file

Reply to Message Icon

Name: L_Plates
Date: February 1, 2009 at 20:12:38 Pacific
OS: Windows XP
CPU/Ram: p4
Product: Acer / 3700
Subcategory: Batch
Comment:

I am new to programming and would like help.
I am trying to create a batch file so that a user input is yes or no. An .ini file would be written based on the answer supplied.

Batch file
q do you want to use the new data?
y/n
if yes then write data.ini with the following
[data]
DatabaseType=ASA
DBMS=ODBC
LogId=
LogPassword=
DbParm=DisableBind=1,DelimitIdentifier='No'
DSN=ABC Server

if no then write data.ini with the following
[data]
DatabaseType=ASA
DBMS=ODBC
LogId=
LogPassword=
DbParm=DisableBind=1,DelimitIdentifier='No'
DSN=DEF Server

Any recommendations would be great. Thanks




Sponsored Link
Ads by Google

Response Number 1
Name: pball
Date: February 1, 2009 at 21:10:28 Pacific
Reply:

test and make sure it gives you what you need.

@echo off
:again
echo do you want to use the new data?
echo type y or n
set /p choice=
if [%choice%]==[] goto again
if [%choice%]==[y] goto 1
if [%choice%]==[n] goto 2
goto again

:1
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=ABC Server>>inifile.ini
goto end

:2
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=DEF Server>>inifile.ini
goto end

:end

-------------

well there is a batch file to do it. just copy and paste and your set.

now for how it works if you want to know.

:again
echo do you want to use the new data?
echo type y or n
set /p choice=
if [%choice%]==[] goto again
if [%choice%]==[y] goto 1
if [%choice%]==[n] goto 2
goto again
that asks the user the question then the if statements check if it was a y or n then goes to the section for the selected answer

:1
echo [data]>inifile.ini
echo DatabaseType=ASA>>inifile.ini
echo DBMS=ODBC>>inifile.ini
echo LogId=>>inifile.ini
echo LogPassword=>>inifile.ini
echo DbParm=DisableBind=1,DelimitIdentifier='No'>>inifile.ini
echo DSN=ABC Server>>inifile.ini
goto end

The :1 is the label the goto looks for. Then echo line is echoed into the file because > is used. if one > is used it will over write the file, but if two > are used it adds to the file. So the first time the file is written over but every other line is added. The goto end goes to the label at the end of the program so the other choices are not ran. The same thing happens for the second choice.

need more help just ask. later


0

Response Number 2
Name: L_Plates
Date: February 1, 2009 at 22:05:58 Pacific
Reply:

This works really well.
You have been a great help.

THANK YOU


0

Response Number 3
Name: Mechanix2Go
Date: February 2, 2009 at 03:54:08 Pacific
Reply:

You can streamline it a bit.

=============================================
@echo off > data.ini & setLocal EnableDelayedExpansion

set /p T=do you want to use the new data?
goto !T!

:Y
>> data.ini echo [data]
>> data.ini echo DatabaseType=ASA
>> data.ini echo DBMS=ODBC
>> data.ini echo LogId=
>> data.ini echo LogPassword=
>> data.ini echo DbParm=DisableBind=1,DelimitIdentifier='No'
>> data.ini echo DSN=ABC Server

goto :eof

:N
>> data.ini echo [data]
>> data.ini echo DatabaseType=ASA
>> data.ini echo DBMS=ODBC
>> data.ini echo LogId=
>> data.ini echo LogPassword=
>> data.ini echo DbParm=DisableBind=1,DelimitIdentifier='No'
>> data.ini echo DSN=DEF Server


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Razor2.3
Date: February 2, 2009 at 08:37:53 Pacific
Reply:

Mechanix2Go: You can streamline it a bit.

I can play that game, too!

@echo off
set dsn=ABC Server
set /p T=do you want to use the new data?
if /i "%T%"=="Y" set dsn=DEF Server

>data.ini (
echo [data]
echo DatabaseType=ASA
echo DBMS=ODBCA
echo LogId=
echo LogPassword=
echo DbParm=DisableBind=1,DelimitIdentifier='No'
echo DSN=%dsn%)

I'll play nice now...

0

Response Number 5
Name: Mechanix2Go
Date: February 2, 2009 at 09:34:51 Pacific
Reply:

Pretty slick, Slick.


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: pball
Date: February 2, 2009 at 12:32:49 Pacific
Reply:

well at least guy who showed me up got shown up in the end. lol


0

Response Number 7
Name: L_Plates
Date: February 2, 2009 at 13:53:04 Pacific
Reply:

LOL
very funny
thanks to all


0

Sponsored Link
Ads by Google
Reply to Message Icon

Change wallpaper with bat... How to fix regedit home p...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to create ini file

Batch command to create .DLL files? www.computing.net/answers/programming/batch-command-to-create-dll-files/15940.html

batch file coverting to VBS file www.computing.net/answers/programming/batch-file-coverting-to-vbs-file/15717.html

Hiding user input in a Batch File www.computing.net/answers/programming/hiding-user-input-in-a-batch-file/15928.html