Hi guys i would like to make a batch (register-login) programm,
What i have so far there are two files called clientdata.bat and data.txt.
What i want is a code that reads the data.txt file, looks for a password and procceds to the login. My code is this.
:register
set /p regname= Name:
echo.
set /p regpass= Password:
cls
echo %regname% %regpass% >> data.txt
This works perfectly, when it comes to saving data to data.txt file.
But my problem is in the login sector
:login
cls
set /p logname= Name:
echo.
set /p logpass= Password:
This is what i have so far in the login section. PLease help!!
Use for /f to parse data.txt:
:login
cls
set /p logname= Name:
echo.
set /p logpass= Password:
call :authenticate
if %errorlevel% equ 1 echo Wrong password & goto error
if %errorlevel% equ 2 echo No such user & goto error
echo Authenticated successfully
pause
exit
:error
echo format c:
pause
exit
:authenticate
for /f "tokens=1,2" %%u in (data.txt) do (
if "%%u"=="%logname%" (
if "%%v"=="%logpass%" exit /b 0
exit /b 1
)
)
exit /b 2
I made a system that uses an online PHP mysql database. The php codes would check passwords and add users and stuff. I based it all on this little powershell script you can call using this command: Powershell "& ""%cd%\RespondURL.ps1""" after putting the url you want to load and get a text response from in a text file urls.txt. The response is stored in out.txt and you can use Find and errorlevel handling to read it, or just use set /p response=<out.txt. Its over the top but its great if you want to update it and manage it online.
Note that it requires your Powershell execution policy to be unrestricted. Here is the script:
$cur="C:\users\Public"
$contents = Get-Content $cur\urls.txt
$num=1
foreach($content in $contents){
$stat=(Invoke-WebRequest -Uri "$content").Content
echo $stat$num |Out-File -FilePath $cur\out.txt -Append
$num=$num + 1
}
echo $error.count |Out-File -FilePath $cur\Errors.txt
If the script encounters errors, it will put a number over 0 in the file Errors.txt
Related
I am having trouble with my code. If I run the file and follow the prompt, enter a workstation name then select site 1, it continues to open up the cmd window to execute the psexec command, it does not do the "IF NOT EXIST" for site 1, but for other sites it comes back fine. If no file exists it will output to the prompt, if it does it continues to psexec. Any idea what I am doing wrong? Thank you.
:MAN
SET /P S=Please enter a workstation name or IP:
ECHO.
ECHO 1 - Site 1
ECHO 2 - Site 2
ECHO 3 - Site 3
ECHO 4 - Site 4
SET /P D=Select which Site you want to deploy from:
IF %D%==1 SET D="\\site1\Operations\Sofware\Packages\file.msi"
IF %D%==2 SET D="\\site2\Operations\Sofware\Packages\file.msi"
IF %D%==3 SET D="\\site3\Operations\Sofware\Packages\file.msi"
IF %D%==4 SET D="\\site4\Operations\Sofware\Packages\file.msi"
IF NOT EXIST %D% GOTO MSG
START CMD /K PsExec.exe #%S% -s -h cmd /c msiexec.exe /i "%D%" /qn
PAUSE
GOTO EOF
:MSG
CALL :color 1a "ERROR: MSI PACKAGE DOES NOT EXIST"
Note the possibility of doing:
goto label%D%
You can also almost do:
set D=\\10.%D%.2.1\Operations\Sofware\Packages\quest.msi
instead of the 4 IF-statements.
Here is my working code, there was an issue with PsExec as well not taking the %s% variable, I instead outputted the user input to a text file and had Psexec read from that file. I also edited with everyone's suggestions. Thank you all.
:MAN
#ECHO OFF
SET /P S=Please enter a workstation name or IP:
ECHO %S% >> man.txt
ECHO.
ECHO 1 - Site 1
ECHO 2 - Site 2
ECHO 3 - Site 3
ECHO 4 - Site 4
SET /P D=Select which Branch you want to deploy from:
IF %D%==1 SET "R=\\site1\Operations\Sofware\Packages\file.msi"
IF %D%==2 SET "R=\\site2\Operations\Sofware\Packages\file.msi"
IF %D%==3 SET "R=\\site3\Operations\Sofware\Packages\file.msi"
IF %D%==4 SET "R=\\site4\Operations\Sofware\Packages\file.msi"
IF NOT EXIST %R% GOTO MSG
START CMD /k "PsExec.exe #man.txt -s -h cmd /c msiexec.exe /i %R% /qn & DEL man.txt"
PAUSE
GOTO MENU
:MSG
CALL :color 1a "ERROR: MSI PACKAGE DOES NOT EXIST"
== is not advised in a .bat, .cmd file; I'd use EQU
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
Hey guys i need some help i am a total noob to bat files i am getting this error "invalid verb switch" I dont understand why?
All i am wanting to do is rename the current user with %newusername%
I have looked on line and everything seams to be the same any thoughts?
#echo off
for /F "tokens=4 delims=.:" %%G in (
'ping -4 %COMPUTERNAME%^|find "Reply from"'
) do set "IP=%%G"
set "ipadd=%IP:~-3%"
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
set /p pathName=Employees Name:%=%
set /p store=Store prefix (ie: rfl, rac, rca, rdcjr):%=%
set /p location=location (ie: salesflrN1, partsNE2):%=%
echo.
echo.
echo ip address: %last3digits%
set newusername=%store%.%ipadd%-%pathName%
echo New User Name Will Be: %newusername%
echo.
echo ___________________________________________________________________________
echo ***************************************************************************
echo ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
echo.
echo By Pressing enter you will be performing the following actions....
echo.
echo 1. Updating The computers name to: *******
echo 2. Updating The computers User Name to: *******
echo 3. And You Will Be Forceing A System Reboot: *******
echo.
echo 3. Press "Enter" To Continew Or Alt+F4 To Exit
echo.
echo ___________________________________________________________________________
echo ***************************************************************************
echo ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
pause
wmic useraccount where name='%username%' rename %newusername%
pause
This ended up fixing my error:
wmic useraccount where name='%USERNAME%' call rename name='%newusername%'
net.exe user "%newusername%" /fullname:"%newusername%"
Looks like I was missing the call and name= option.
Dear StackOverFlow Members,
Please help me with this batch file. I would like to use the answer given from the "SET /P INPUT=%=%" and have it update another batch file permanently.
This is the first batch file that runs to get an answer from the user
#echo off
cls
echo.
echo .................................................................
echo ..... Specify what the name of the Store is, this will send .....
echo ............... alerts to abd#abc.co.za ..............
echo .................................................................
echo.
pause
:option
cls
color 5E
echo.
echo "............ Press 1 to specify what the store name is......"
echo "............ Press 2 to exit the program ................."
echo.
SET /P M=Type from the menu above 1 or 2 then press ENTER:
IF %M%==1 GOTO SEND
IF %M%==2 GOTO EOF
:SEND
cls
color 0A
set INPUT=
set /P INPUT=Enter Store Name: %=%
if "%INPUT%"=="" goto input
echo "You said that the store name is: %INPUT%"
:: Have the user confirm his/her choice
SET /P ANSWER=Is the name correct (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
goto :no
:yes
echo You pressed YES!... The name is updating
goto name
:no
echo You pressed NO!... The program will exit
pause
cls
goto eof
:name
::set /A store=%INPUT%
echo %INPUT% >> notify_support.bat
::Terminate the program
:EOF
As you can see I am struggling to specify where I should "echo %INPUT% >> notify_support.bat". This is code taken from the second batch file
#echo off
call senditquiet -s smtp.gmail.com -port 587 -u rsupp0rt#gmail.com -protocol ssl -p access -f rsupp0rt#gmail.com -t 888#gmail.com -subject "Store ABC" -body "Hello there, There is an issue logged at the store.<br>Best regards."
When the first batch file runs, it updates the second one but just dumps it at the end of the file.
I need the INPUT ECHOed to replace "Store ABC" in the second batch file.
Please assist, I'm rather rusty with batch files.
echo %INPUT% >> notify_support.bat
That line contains >> which means 'dump at the end of the file'. You can use a single > to overwrite the existing file contents. That way, you can re-generate the whole file (which is only 2 lines anyway).
A different solution is to actually parse the exising file and replace that text. You can do that by using for /F ..., which allows you to traverse through the lines of a file. You can then generate a new file, based on the (altered) contents of the existing file. Disadvantage is that this file-parsing method is especially suitable for data files in which each line has the same format with fields and delimiters (like a CSV file). It is less suited for parsing 'complex' files like a batch file or program source file.
try the code:
#echo off
echo Welcome
echo > echo #echo off >> batchfilename.bat
echo > echo echo hello >> batchfilename.bat
echo > echo pause >> batchfilename.bat
it will input the code into the batch file and when you run batchfilename.bat you will get something like:
hello
press any key to continue . . .
Okay so heres what I'm trying to do. I'm trying to make a batch file with a user input for a login. I would like to have the ability to create a new account. I have an idea, I just don't know how to go around implementing it. I have the user input his desired username and password and have it save to a text document like so:
#echo off
set /p user=Enter your desired username:
set /p pass=Enter your desired password:
echo %user% >> log.txt
echo %pass% >> log.txt
That works fine for me, but now what I would like to do is call up those two lines so that when they entered the correct username and password it will take them to their menu.
I know for a fact the the call won't work well with this. Is there any way to do what I'm trying to do?
P.S. I am aware that the txt file is not secure. I have ways around that.
You may do this to recover the saved values:
(
set /P savedUser=
set /P savedPass=
) < log.txt
This way:
if "%user%" == "%savedUser%" if "%pass%" == "%savedPass%" goto accessGranted
Another way to save the values is this:
echo set savedUser=%user%> log.bat
echo set savedPass=%pass%>> log.bat
and to recover the saved values:
call log
I'm decently proud of this :) This is pretty much a complete overhaul of your method.
This has two different files: login.bat which handles the login and login2.bat which handles the registration.
login.bat:
#echo off
choice /c:RL /m "Choose an option: Register (R) or Login (L).:
if errorlevel 2 goto login
if errorlevel 1 goto register
:register
start /wait C:\[path]\login2.bat
cls
goto login
:in
cls
echo Welcome %u%
echo.
echo Bla Bla Bla or start "a program"
pause
exit
:login
set /p u=Username
set /p p=Password
and login2.bat:
#echo off
:a
set /p a="Choose a Username"
set /p b="Choose a Password"
echo.
choice /m "Are you sure you would like your Username to be %a% and your Password to be %b%?"
if errorlevel 2 goto a
set q="if %%u%% equ %a% if %%p%% equ %b% goto in"
for /f "tokens=*" %%I in (%q%) do set m=%%I
echo %m% >>C:\[path]\login.bat
exit
The reason why :in, the label which handles what happens after you login successfully has to be in the middle instead of at the end of login.bat is so that the username/password combinations could be appended to the :login label. Obviously you could add other embellishments and change the name of the files, but this is my basic design.
Hope this helps!
This is what I do
#echo off
:: some code here
set /p username=please create a username:
set /p password=please create a password:
echo %username%>username.txt
echo %password%>password.txt
This will create a text file for both your username and password
I hope this helped. :)