Batch file to create ini file

Acer / 3700
February 1, 2009 at 20:12:38
Specs: Windows XP, p4
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



See More: Batch file to create ini file

Report •


#1
February 1, 2009 at 21:10:28
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


Report •

#2
February 1, 2009 at 22:05:58
This works really well.
You have been a great help.

THANK YOU


Report •

#3
February 2, 2009 at 03:54:08
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


Report •

Related Solutions

#4
February 2, 2009 at 08:37:53
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...

Report •

#5
February 2, 2009 at 09:34:51
Pretty slick, Slick.


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

M2


Report •

#6
February 2, 2009 at 12:32:49
well at least guy who showed me up got shown up in the end. lol

Report •

#7
February 2, 2009 at 13:53:04
LOL
very funny
thanks to all

Report •


Ask Question