I have made a litle batch file,
where you need to insert your account name of your computer.
I'm wondering if you could maybe write the account name to a text file,
so the program could remember it for next time you open it.
and don't have do enter it twice on the same computer.
What about this?
#echo off
echo Prevous value is:
echo %mysetting%
echo.
set /p input="Enter new value: "
setx mysetting %input%
pause
Save this as .bat and run twice to see the persistence.
setlocal EnableDelayedExpansion
if exist username.txt (
REM Read from text file:
set /p "user="<username.txt
) else (
REM Read from keyboard:
set /p "user=Enter your username: "
REM Write to text file:
echo !user!>username.txt
)
Related
:start
echo Try to hack this password!
set/p "pass=>"
if not %pass% == Ebaturvaline177 goto vale
echo Correct!!
pause
start "" https://stackoverflow.com
exit
:vale
echo Wrong.
goto :start
How can I encrypt/hash the password so people just cant view the code and see the code?
I was interested after reading your question so i decided to make a batch-file that is kind of accomplishing what you are trying to do. instead of storing raw password i am storing MD5 Hash in a file and then i am comparing user input that is also hashed with the hash stored in a file named pass.txt.
Crackme.bat:
#echo off & setlocal
:loop
set userinput=
set /p userinput=Try Crack me:
set "plaintext=%userinput%"
set "file=%temp%\%~n0.tmp"
set md5=
if not defined plaintext set /P "plaintext="
if exist "%plaintext%" (
set "file=%plaintext%"
) else for %%I in ("%file%") do if %%~zI equ 0 (
<NUL >"%file%" set /P "=%plaintext%"
)
for /f "skip=1 delims=" %%I in ('certutil -hashfile "%file%" MD5') do (
if not defined md5 set "md5=%%I"
)
2>NUL del "%temp%\%~n0.tmp"
echo %md5: =% >>file.txt
set /p passhash=<file.txt
ping localhost -n 2 >nul
del file.txt
set /p passtocrackhash=<pass.txt
if %passhash% equ %passtocrackhash% ( goto cracked) else ( goto error)
:error
echo Wrong pass
goto loop
:cracked
echo Hurrah!you cracked the password it was %userinput%
This batch file will take user input and compare it with the hash stored in pass.txt,if the password is correct then a success message is shown otherwise an error is thrown and is looped back for another try
pass.txt:
8b1a9953c4611296a827abf8c47804d7
Just make a file named as pass.txt and type the md5 hash of your password and save it.you can create an md5 hash from following batch-file or online . Just save the code as .bat open cmd in same directory and give the string that you want to hash as an argument to batch file
Well anyone is welcomed to edit the code for improvement...
If the user has access to the source code, they have access to bypass the password.
If it's just a fun challenge, you could try hashing the input and checking against the hashed version of your password instead of storing plaintext.
This would require some file system management, however. I do not know of a way to hash input to a batch file directly.
Step for only one time
First time when the user executes the Batch file - 'Test.bat' it should prompt the user for Directory path & move the path to a text file - Path.txt and proceed with next step :Nextcommand
Step for Everytime
When the User runs the same batch file - 'Test.bat' from Second time, it should check for the existence of the above file 'Path.txt' in the above user specified directory and if available then proceed to next step :Nextcommand else have to create the file as specified in the above step.
My Code
echo off
#echo off
IF EXIST "%FileLoc%\FileLocationPath.txt" GOTO :NextCommand
set loc= Enter File Location:
set /p FileLoc=%loc%
#echo %FileLoc%>>FileLocationPath.txt
GOTO :NextCommand
For information to survive, you need to write it to a file (there are other possibilities, like Registry, but a file is the easiest solution)
#echo off
setlocal
IF EXIST "FileLocationPath.txt" (
<"FileLocationPath.txt" set /p FileLoc=
goto :NextCommand
)
set /p "FileLoc=Enter File Location: "
>"FileLocationPath.txt" echo %FileLoc%
:NextCommand
echo using %FileLoc%
If you ever need to reset the default, just delete the file.
This should be what you want.
#echo off
setlocal enabledelayedexpansion
call :check
if defined FileLoc (
echo %FileLoc%
pause
) else (
set /p "FileLoc=Enter File Location: "
echo/>>"%0"
echo set "FileLoc=!FileLoc!">>"%0"
)
goto :eof
:check
It will check the existance of the variable, which at first will not exist, User will enter it, then once user entered the location, it will store that location as a variable below the :check label. Each time from now when the script is ran, the check label is called and the already set location is set.
I have sql files in a folder structure like the following :
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer1\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer2\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer3\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer4\test.sql
........
I want to make a script which reads the path (C:\Users\Peter\Desktop\SQL_FILES),
the name of the file(test.sql) and a text
and then concatenate the text in the end of each test.sql file.
Could you help me please ?
Thanks in advance
:: Hide Command and Set Scope
#echo off
setlocal EnableExtensions
mode 140,50
set /p AbsolutePath="Enter the path of root folder :"
echo.
set /p FileName="Enter the filename with it's extension (ie. test.sql):"
echo.
echo Enter your inserts
echo Press Enter twice when finished
echo (text may not contain ^<, ^>, ^|, ^&, or un-closed quotes)
ver > NUL
set new_line=""
:still_typing
set /p new_line=">"
if errorlevel 1 echo. >> temp.txt & set /p new_line=">"
if errorlevel 1 echo Sending message. . . & goto done_typing
echo %new_line% >> temp.txt
goto still_typing
:done_typing
echo done
:End
endlocal
pause >nul
=====================================
For example :
The file test.sql for example contains initially :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
And after the execution of batch supposing I add an empty line and two inserts in the text :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (1,2,3);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (2,3,4);
The Batch file below use a different method to do the same, but in a simpler way. This code may be modified in any point you wish; for example, if you want not that the filename must include a wild-card.
#echo off
setlocal
set /p "AbsolutePath=Enter the path of root folder: "
echo/
set /p "FileName=Enter the filename with a wild-card (ie. test*.sql): "
echo/
echo Enter your inserts
echo Press Ctrl-Z and Enter when finished
copy CON temp.txt > NUL
echo/
echo Typing done
echo/
for /R "%AbsolutePath%" %%a in (%FileName%) do type temp.txt >> "%%a"
right now i'm working on a batch file that has a simple login and register feature. While I can register a user by creating a .txt file for their username and password, I cant figure out how to convert the contents of the .txt file into a variable that I can then test for to login the user. Here is what I have now. My problem is at :sign .
#echo off
title Login
:a
cls
mode con: lines=10 cols=25
echo _________________________
echo Select Your Choice
echo 1) Login
echo 2) Register
echo _________________________
set /p begi=:
if '%begi%'=='2' goto reg
if '%begi%'=='1' goto sign
:reg
cls
set u=
set /p u=Enter Your Username:
pause>nul
cls
set p=
set /p p=Enter your Password:
pause>nul
#echo %u% > user.txt
#echo %p% > pass.txt
pause>nul
goto a
:sign
cls
exit
REM write to the file:
echo Username>user.txt
REM read from the file (first line only):
set /p "un="<user.txt
echo %un%
by the way:
your line #echo %u% > user.txt writes the variable plus a space to the file. This space will be part of the new variable (and will make trouble when using the new variable), if you read this file in. To avoid it, write #echo %u%>user.txt
I want to copy a file with set /p. Task: Write a file name with set /p and that will be copied in a directory that I want, but it doesn't work.
My current source:
#echo off
echo Enter YOur Pic Name With .jpg
set /p cop=
xcopy /s %systemroot%\%cop% %systemroot%\system32\oobe\info\backgrounds
cls
pause
For the SET /P command, the format works best like this:
set /p cop=Enter your Pic name with .jpg
I'd also suggest you add a couple of lines to check if the file is actually there:
#rem just check that the full path is what I expect
echo %systemroot%\%cop%
#rem and check if the file is there
dir %systemroot%\%cop%
(Delete these lines once your batch file is working).
Also, delete the cls line, until it's working. Then, once it's doing what you need, you can put it back in, if you want.
You might want to think about whether %systemroot% is the right place for these pictures, even temporarily. It's usually used for Windows OS code.
It is possible that %systemroot% path may have spaces, so file names must be enclosed in quotes:
#echo off
set /p "cop=Enter YOur Pic Name With .jpg: "
xcopy /s "%systemroot%\%cop%" "%systemroot%\system32\oobe\info\backgrounds"
cls
pause
try running as admin: http://windows.microsoft.com/en-us/windows7/how-do-i-run-an-application-once-with-a-full-administrator-access-token
also you may try the following (xcopy doesn't like the /s), I think you're trying to silence the output, just try with the >nul redirect:
#echo off
echo Enter YOur Pic Name With .jpg
set /p cop=
xcopy /y %systemroot%\%cop% %systemroot%\system32\oobe\info\backgrounds\* >nul
cls
pause