how to link batch file with .ini or .txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vip
Posts: 4
Joined: 14 Sep 2009 11:16
Location: India

how to link batch file with .ini or .txt

#1 Post by vip » 14 Sep 2009 11:25

i have following batch file

connect.bat
@Echo Off
SetLocal
(Set RAS_con=connection)
(Set RAS_usr=user)
(Set RAS_pwd=password)
:Online_check
Rasdial | Find /V /N "" | FindStr /R "^\[3\]" && (
Echo %DATE% %TIME% -- Still online. Delaying 60s...
Ping -n 61 localhost > NUL
Goto Online_check)
Echo %DATE% %TIME% -- Offline. Reconnecting to "%RAS_con%"...
Rasdial "%RAS_con%" %RAS_usr% %RAS_pwd% && Goto Online_check
Echo %DATE% %TIME% -- Error connecting to "%RAS_con%".
EndLocal

and i want to link it to a .ini or .txt file which contain connection,user and
password

for e.g. a info.ini can be like this

info.ini
(Set RAS_con=connection)
(Set RAS_usr=user)
(Set RAS_pwd=password)

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 14 Sep 2009 12:18

Easiest thing to do is set the INI file as just another CMD file and call it:


info.cmd

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password


connect.cmd

Code: Select all

@echo off
call info.cmd
:online_check
. . . .



If you insist on using an extension of INI then you can do this:


info.ini

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password



connect.cmd

Code: Select all

@echo off
for /f "delims=" %%a in (info.ini) do %%a
:online_check
. . . .

vip
Posts: 4
Joined: 14 Sep 2009 11:16
Location: India

#3 Post by vip » 25 Sep 2009 10:34

avery_larry wrote:Easiest thing to do is set the INI file as just another CMD file and call it:


info.cmd

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password


connect.cmd

Code: Select all

@echo off
call info.cmd
:online_check
. . . .



If you insist on using an extension of INI then you can do this:


info.ini

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password



connect.cmd

Code: Select all

@echo off
for /f "delims=" %%a in (info.ini) do %%a
:online_check
. . . .



thank u sooooooooo.... much

in first step i did following things:

connect.cmd

Code: Select all


@Echo Off
call info.cmd
 :Online_check
  Rasdial | Find /V /N "" | FindStr /R "^\[3\]" && (
    Echo %DATE% %TIME% -- Still online. Delaying 60s...
    Ping -n 61 localhost > NUL
    Goto Online_check)
  Echo %DATE% %TIME% -- Offline. Reconnecting to "%RAS_con%"...
  Rasdial "%RAS_con%" %RAS_usr% %RAS_pwd% && Goto Online_check
  Echo %DATE% %TIME% -- Error connecting to "%RAS_con%".
  EndLocal


info.cmd

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password



and it works perfectly

IInd step:

connect.cmd

Code: Select all


@Echo Off
for /f "delims=" %%a in (info.ini) do %%a
 :Online_check
  Rasdial | Find /V /N "" | FindStr /R "^\[3\]" && (
    Echo %DATE% %TIME% -- Still online. Delaying 60s...
    Ping -n 61 localhost > NUL
    Goto Online_check)
  Echo %DATE% %TIME% -- Offline. Reconnecting to "%RAS_con%"...
  Rasdial "%RAS_con%" %RAS_usr% %RAS_pwd% && Goto Online_check
  Echo %DATE% %TIME% -- Error connecting to "%RAS_con%".
  EndLocal


info.ini

Code: Select all

Set RAS_con=connection
Set RAS_usr=user
Set RAS_pwd=password



but in second step a error message appears like below:

Image

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 28 Sep 2009 12:08

Get rid of the @echo off and see if you can tell what's messing up.

vip
Posts: 4
Joined: 14 Sep 2009 11:16
Location: India

#5 Post by vip » 30 Sep 2009 08:01

i repeat IInd step and this time it works perfectly


thanx.....

vip
Posts: 4
Joined: 14 Sep 2009 11:16
Location: India

#6 Post by vip » 30 Sep 2009 08:07

and one more thing is there any way to encrypt password for e.g. when we run connect.cmd it prompt for connection name user name password and then 1. press 1 to save info
2. press 2 not to save info
and save this info into info.ini with encrypted password.

Post Reply