Page 1 of 1

how to link batch file with .ini or .txt

Posted: 14 Sep 2009 11:25
by vip
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)

Posted: 14 Sep 2009 12:18
by avery_larry
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
. . . .

Posted: 25 Sep 2009 10:34
by vip
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

Posted: 28 Sep 2009 12:08
by avery_larry
Get rid of the @echo off and see if you can tell what's messing up.

Posted: 30 Sep 2009 08:01
by vip
i repeat IInd step and this time it works perfectly


thanx.....

Posted: 30 Sep 2009 08:07
by vip
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.