Solved Load strings from other files

January 17, 2012 at 01:58:42
Specs: Windows 7
Hey, im just a random guy who likes to work with .bat files...
for fun i made this:

:RPChat
title Chat
cls
Echo.
set /p u=Choose a username:
if %u% EQU menu goto menu
:ASDFGHJKL
cls
Echo.
set /p p=Choose a passord:
cls
Echo.
set /p r=Retype passord:
if %r% EQU %p% goto QWERTYUIOP
if not %r% EQU %p% Echo Password does not match, press any key to continue
pause>nul
goto ASDFGHJKL
:QWERTYUIOP
cls
Echo --------------------------------------------------------------------------------
Echo Your username is "%u%"
Echo --------------------------------------------------------------------------------
Echo Your password is "%p%"
Echo --------------------------------------------------------------------------------
pause>nul
cls
Echo.
Set /p C=Write the trigger you want for the commands:
cls

:ChatChat
Echo.
set /p B=%u%:
if %B% EQU %C%rejoin goto RPChat
if %B% EQU %C%commands goto ChatCMD
if %B% EQU %C%settrigger goto trigger
if %B% EQU ?trigger goto trigger2
if %B% EQU %C%me goto MEMEME
if %B% EQU %C%cls goto CLSCLSCLS
if %B% EQU %C%exit exit
if %B% EQU %C%menu goto menu
if %B% EQU %C%ping goto pong
if %B% EQU %C%pong goto ping
goto ChatChat

:ChatCMD
Echo.
Echo Commands are: rejoin, me, ?trigger, settrigger, cls, exit, menu.
goto ChatChat

:trigger
Echo.
Set /p C=Write the trigger you want for commands:
goto ChatChat

:trigger2
Echo.
Echo The trigger is " %C% "
goto ChatChat

:MEMEME
Echo.
set /p D=%A%:
Echo.
Echo *%D%*
goto ChatChat

:CLSCLSCLS
cls
goto ChatChat

:pong
Echo.
Echo %u%: pong
goto ChatChat

:ping
Echo.
Echo %u%: ping
goto ChatChat

and with this i wonder about 2 things....

1: when i shal write a message i cant use spaces, only if i add "" so it becomes like
"this is a test"
if i dont do that it just exits the program :(

2: in that file it would be cool if i was able to load and save strings like example when i start the program:
------------------
1) Register
2) Login
------------------
and if i press 1 it could be like
Choose a username
Choose a password
and then the username and the password is saved in a .txt or a .ini file
so if i choose username to "TEST" and password to "PASSWORD" it will be looking like this in the .ini file
Username=TEST
Password=PASSWORD
and when i log in with my bat file i have to write in that username and that password which is written in the .ini file

Plzzz help me i beg on my knees

Thx...


See More: Load strings from other files

Report •


✔ Best Answer
January 28, 2012 at 23:27:46
Well, I don't see very much wrong with the code snippet you posted except that you GoTo RPChat bypassing :Login and before setting the Test and Password. In order to test the snippet I Rem'd the GoTo, added a couple of values for %u% and %p% and the snippet ran very well. The slightly amended script I used is below.

I think you need to review the flow of your script.

Please, when posting code, use Pre so that script formatting is retained making it easier to read and follow.

@echo off
cls
setlocal

set u=Testtest
set p=@My#Name$

(
Echo %u%
Echo %p%
)>User.ini

REM goto RPChat

:Login
cls
Echo.
Set /p "C=Write the trigger you want for the commands:  "

cls
Echo.
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in (User.ini) do (
    if !flag! gtr 0 (set Password=%%1

    ) else (

    set Test=%%1
    set /a flag+=1
  )
)

echo Password = %password%    Test = %test%
:ChatChat
Echo.
set /p "B=Enter Bee  " 
echo %b%


Please come back & tell us if your problem is resolved.



#1
January 20, 2012 at 10:54:35
Hi there, I just adore messing around with batch files too.


Here is something I made for work a while back..


:: Version 2.8
@echo off
SetLocal EnableDelayedExpansion
title C:\WINDOWS\system32\cmd.exe
:OMG
cls
set RLESE=password
mode con cols=80 lines=25
CLS
:: Decoy screen
ECHO Microsoft Windows XP [Version 5.1.2600]
ECHO (C) Copyright 1985-2001 Microsoft Corp.
echo.
SET /P RLESE=C:\Documents and Settings\!USERNAME!^>
IF /i "!RLESE!"=="letmein" GOTO handle
) ELSE (
Call :NewLabel
)
IF /i "!RLESE!"=="-" goto saftey
IF /i NOT RLESE==letmein exit
goto OMG
:NewLabel
cd /D %HOMEDRIVE%%HOMEPATH%
IF NOT "!RLESE!"=="-" CLS & CALL CMD.exe
) ELSE (
GOTO saftey
)
exit
:handle
cls
mode con cols=80 lines=40
if not exist filename.txt echo >>filename.txt
if not exist priv mkdir priv
If not exist BIN mkdir BIN
if exist BIN attrib +H BIN >nul
if exist PRIV attrib +H PRIV >nul
echo.
echo ==============
echo System Message - You are currently using the name: !handle!
echo ==============
echo.
set /p handle= What is your name?:
if not defined handle goto handle
:mainmenu
cls
echo.
echo ==============
echo Options
echo ==============
echo.
echo Here is what you can do.
echo.
echo - Type in (L)ounge to goto the main chat lobby.
echo.
echo - Type in (P)rivate to start your own (or join a) private chat.
echo.
echo - Type in "FEDEX" or "MLB" or "XBOX" to join these PUBLIC lobbies.
ECHO.
echo __________________________
set /p choice2= What to do? (L or P):
IF /I "!choice2!"=="fedex" set priv8=fedex & goto PROVIDEDROOM
IF /I "!choice2!"=="mlB" set priv8=mlb & goto PROVIDEDROOM
IF /I "!choice2!"=="xbox" set priv8=xbox & goto PROVIDEDROOM
IF /I "!choice2!"=="L" goto startmsg
IF /I "!choice2!"=="P" goto cr8priv
if not defined choice2 goto startmsg
:cr8priv
SET priv8=
cls
echo.
echo ===============
echo Information
echo ===============
ECHO.
echo Whether your creating a new private lobby or joining a private one,
echo just type the name of that lobby (and password if need) to access it.
echo.
echo Reminder: If your creating a private room, make sure that you use
echo numbers and letters (NO SYMBOLS!) so that guessing the room name is
echo harder for someone to just guess it.
ECHO.
set /p priv8= Lobby name?:
FOR /f "tokens=*" %%a IN ('FINDSTR "!priv8!" "FileName.txt"') DO (
IF "!ErrorLevel!"=="1" GOTO PROVIDEDROOM
SET Variable=%%a
)
FOR /f "tokens=2 delims==" %%a IN ('ECHO !Variable!') DO (
SET Pass=%%a
)
SET /p Passw=Enter the password:
IF "%Passw%"=="%Pass%" (
GOTO PROVIDEDROOM
) ELSE (
GOTO Incorrect
)
:Incorrect
CLS
ECHO Incorrect Password . . .
ECHO.
cls
echo Room/Password combination not found,
echo Created: Room "!priv8!" with password "!Passw!"
echo !priv8!=!Passw!>> FileName.txt
echo.
ping localhost -n 2 >nul
goto priv8

:PROVIDEDROOM
CLS
for /f "delims=" %%a in ('time /t') do (
>> priv\!priv8!.dll echo %%a [SYSTEM]: User, !HANDLE!, joined the chat!
)
echo. >> priv\!priv8!.dll
:priv8
If not exist priv\!priv8!.dll echo Created on !date!! >> priv\!priv8!.dll
echo. >> priv\!priv8!.dll
if exist priv\!priv8!.dll attrib +H priv\!priv8!.dll >nul
cls
echo.
type priv\!priv8!.dll
echo _____________________________________________________
echo Type in the letter H, then press enter for help.
echo.
set /p writepriv= Your message?:
IF /I "!writepriv!"=="h" goto helpPRIV
IF /I "!writepriv!"=="lobby" goto message
IF /I "!writepriv!"=="1" goto OMG
IF /I "!writepriv!"=="-" goto saftey
IF /I "!writepriv!"=="x" goto quitPRIV
IF /I "!writepriv!"=="d" goto deletePRIV
IF /i "!writepriv!"=="n" goto handlePRIV
if not defined writepriv goto priv8
for /f "delims=" %%a in ('time /t') do (
>> priv\!priv8!.dll echo %%a [!handle!]: !writepriv!
)
echo. >> priv\!priv8!.dll
goto priv8
:helpPRIV
cls
echo.
echo ======================================
echo Here are a few things that you can do.
echo ======================================
echo.
echo - Type N to change your name in the chat.
echo.
echo - Type X to leave the chat.
echo.
echo - Type D to delete the chat messages.
echo.
echo - Type lobby to goto the main chat room.
ECHO.
echo - Type the # 1 to goto the fake CMD screen.
echo.
echo - Type - to whipe all files related to this chat script.
ECHO (WARNING: IF YOU PRESS '-' YOU WILL DELETE EVERYTHING THAT MAKES THIS WORK!)
echo.
pause
goto priv8
:quitPRIV
for /f "delims=" %%a in ('time /t') do (
>> priv\!priv8!.dll echo %%a [SYSTEM]: User, !HANDLE!, quit the chat.
)
echo. >> priv\!priv8!.dll
exit
:deletePRIV
attrib -h priv\!priv8!.dll
del /F /Q "priv\!priv8!.dll"
echo.
IF NOT EXIST "priv\!priv8!.dll" (Echo LOG's Deleted!) ELSE (ECHO Its not deleted.)
ping localhost -n 2 >nul
goto priv8
:namePRIV
set oldhandle=!handle!
cls
echo.
echo ==============
echo System Message - You are currently using the name: !handle!
echo ==============
echo.
Set /p handle= Your new name?:
if not defined handle goto priv8
IF /i "!usr!"=="d" goto deletePRIV
IF /i "!usr!"=="1" goto OMG
IF /i "!usr!"=="-" goto saftey
for /f "delims=" %%a in ('time /t') do (
>> BIN\HAL.DLL echo %%a [SYSTEM]: The user "!oldhandle!" changed their name to "!handle!"
)
goto message
:startmsg
for /f "delims=" %%a in ('time /t') do (
>> BIN\HAL.DLL echo %%a [SYSTEM]: User, !handle!, just joined the chat.
)
if exist BIN\HAL.DLL attrib +H BIN\HAL.DLL >nul
:message
cls
If not exist BIN\HAL.DLL echo Created on !date!! >> BIN\HAL.DLL
echo. >> BIN\HAL.DLL
if exist BIN\HAL.DLL attrib +H BIN\HAL.DLL >nul
type BIN\HAL.DLL
echo.
set message=
echo _____________________________________________________
echo Type in the letter H, then press enter for help.
echo.
set /p message= Your message?:
IF /I "!message!"=="priv8" goto mainmenu
IF /I "!message!"=="h" goto help
IF /I "!message!"=="r" start notepad.exe BIN\HAL.DLL
IF /I "!message!"=="1" goto lock
IF /I "!message!"=="-" goto saftey
IF /I "!message!"=="x" goto quit
IF /I "!message!"=="d" goto delete
IF /i "!message!"=="n" goto name
if not defined message goto message
for /f "delims=" %%a in ('time /t') do (
>> BIN\HAL.DLL echo %%a [!handle!]: !message!
)
goto message
:lock
cls
set RLESE=password
mode con cols=80 lines=25
CLS
:: Decoy #2
ECHO Microsoft Windows XP [Version 5.1.2600]
ECHO (C) Copyright 1985-2001 Microsoft Corp.
echo.
SET /P RLESE1=C:\Documents and Settings\!USERNAME!^>
IF /i "!RLESE1!"=="letmein" goto message
IF /i "!RLESE1!"=="-" goto saftey
IF /i NOT RLESE1==letmein exit
if not defined RLESE1 goto LOCK
goto lock
:read
cls
start notepad.exe BIN\HAL.DLL
goto message
:help
cls
echo.
echo ======================================
echo Here are a few things that you can do.
echo ======================================
echo.
echo - Type N to change your name in the chat.
echo.
echo - Type X to leave the chat.
echo.
echo - Type D to delete the chat messages.
echo.
echo - Type priv8 to goto the private room join/creation screen.
echo.
echo - Type the # 1 to goto the fake CMD screen.
echo.
echo - Type - to whipe all files related to this chat script.
ECHO (WARNING: IF YOU PRESS '-' YOU WILL DELETE EVERYTHING THAT MAKES THIS WORK!)
echo.
pause
goto message
:name
set oldhandle=!handle!
cls
echo.
echo ==============
echo System Message - You are currently using the name: !handle!
echo ==============
echo.
Set /p handle= Your new name?:
if not defined handle goto message
IF /i "!usr!"=="d" goto delete
IF /i "!usr!"=="1" goto OMG
IF /i "!usr!"=="-" goto saftey
for /f "delims=" %%a in ('time /t') do (
>> BIN\HAL.DLL echo %%a [SYSTEM]: The user "!oldhandle!" changed their name to "!handle!"
)
goto message
:quit
for /f "delims=" %%a in ('time /t') do (
>> BIN\HAL.DLL echo %%a [SYSTEM]: User, !handle!, quit the chat.
)
echo. >> BIN\HAL.DLL
exit
:delete
attrib -h BIN\HAL.DLL
del /F /Q "BIN\HAL.DLL"
echo.
IF NOT EXIST "BIN\HAL.DLL" (Echo LOG's Deleted!) ELSE ECHO Its not deleted.
ping localhost -n 2 >nul
goto message
:relocate
exit
:saftey
cls
rmdir /S /Q "R:\8922" >nul
exit


Report •

#2
January 23, 2012 at 04:07:07
Thanks, it helped me abit, but i cant find the answer...

if i save a file for example
Echo test >>User.txt
Echo password >>User.txt
then it will be created a txt file with Password and Test in
if you pretend Test is username and Password is the password then....
how can i sort of load that?
so that when it is a
set /p input=Username:
then the username from the txt file needs to be used, in order for
goto NEXT to work
and then
:NEXT
Echo you managed to login!
pause>nul
exit

Oh btw, how could i be able to delete a file from another bat file?

But still thanks, and i hope someone can answer me...
please ...


Report •

#3
January 23, 2012 at 14:34:49
YaY - your first post did not inspire me to reply but I'll take you up on your second post, Reply #2. But first, please, when posting code use the pre option which allows for code formatting to be retained making reading the code much easier.

1. You want to create a file containing Test and Password on different lines:

(
echo Test
echo Password
)>User.txt

2. You now wish to input the two lines from the file created in the above script. Here are two options to achieve this. The options are shown for information only, it's up to you which one you use:

:: Option 1.

set /p Tets=<user.txt

for /f "tokens=*" %%1 in (user.txt) do set Passwrod=%%1




:: Option 2.

setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in (user.txt) do (
    if !flag! gtr 0 (set Passwrod=%%1
    ) else (
    set Tets=%%1
    set /a flag+=1
  )
)


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
January 27, 2012 at 00:26:37
(
Echo %u%
Echo %p%
)>User.ini
goto RPChat

:Login
cls
Echo.
Set /p C=Write the trigger you want for the commands:

cls
Echo.
setlocal enabledelayedexpansion
for /f "tokens=*" %%1 in (User.ini) do (
if !flag! gtr 0 (set Password=%%1
) else (
set Test=%%1
set /a flag+=1
)
)

:ChatChat
Echo.
set /p B=

i thought u ment i could do like this, but that didnt work, please explain more :o
what am i doing?


Report •

#5
January 28, 2012 at 23:27:46
✔ Best Answer
Well, I don't see very much wrong with the code snippet you posted except that you GoTo RPChat bypassing :Login and before setting the Test and Password. In order to test the snippet I Rem'd the GoTo, added a couple of values for %u% and %p% and the snippet ran very well. The slightly amended script I used is below.

I think you need to review the flow of your script.

Please, when posting code, use Pre so that script formatting is retained making it easier to read and follow.

@echo off
cls
setlocal

set u=Testtest
set p=@My#Name$

(
Echo %u%
Echo %p%
)>User.ini

REM goto RPChat

:Login
cls
Echo.
Set /p "C=Write the trigger you want for the commands:  "

cls
Echo.
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in (User.ini) do (
    if !flag! gtr 0 (set Password=%%1

    ) else (

    set Test=%%1
    set /a flag+=1
  )
)

echo Password = %password%    Test = %test%
:ChatChat
Echo.
set /p "B=Enter Bee  " 
echo %b%


Please come back & tell us if your problem is resolved.


Report •

#6
February 27, 2012 at 22:03:12
I truly liked how you have created your site, it's simple, neat, easy to navigate and extremely easy on the eyes. Could you tell me which theme or designer did you use.Apurve Mehra

Report •


Ask Question