bat file Error "invalid verb switch" when using wmic - batch-file

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.

Related

User Input Batch File crashes # echo var

I am writing a basic batch script and I need to acquire user input.
The script appears to crash when I call the user input vars in an echo command.
(This is probably something very basic but I can't see the error...)
#echo off
echo ********************************
echo SHUTDOWN/RESTART
echo ********************************
echo.
set /p answer="Restart (R) or Shutdown(S)? "
set /p time="How soon ? "
echo you have selected %answer% in %time% seconds.
if "%answer%"=="" goto error
if "%time%"=="" goto error
if "%answer%"=="R" (
goto restart
) else (
goto shutdown
)
echo.
echo.
:restart
FOR /L %%AA IN (1,1,%1) DO (
echo Restarting in %%AA ...
)
The FOR command requires a single alphabetic character for its controlled variable. %AAA is invalid.

Batch login system

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

Setting User account "Full Name" and "Description" from within a batch using variables

I am attempting to write a batch script that adds new users to a machine using user prompts to get the information. I am at the point where the user gets created correctly, but the "Full Name" and "Description" fields don't populate, no matter what I try. I can't seem to get it to pass the %fullname% variable into either the net user command or the wmic command. If I just type quoted text into either spot it adds the information properly. Also if there's a better way to do echos like that it would be appreciated, takes up too many lines IMO. :)
:User
echo.
echo Please Input Username...
echo.
set /p username=Username:
echo.
echo Please Confirm Username...
echo.
set /p confirm=Username:
if '%username%' == '%confirm%' (
echo.
echo Please Input User Full Name...
echo.
set /p fullname=Full Name:
echo.
echo Please Input User Description...
echo.
set /p description=Description:
echo Creating %username%...
net user %username% * /add /active:yes /fullname:%fullname% /comment:%description% /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE
wmic useraccount where "Name='%username%'" set FullName=%fullname%
This script creates the user just fine, but the fullname and comment fields are blank.
Problem solved. Apparently the parentheses for my if statement were messing everything up. The fullname and description variables were blank for whatever reason. I guess you can't do a set inside an if statement?
No matter, changing to this has solved the problem and it works perfectly now.
:User
echo.
echo Please Input Username...
echo.
set /p username=Username:
echo.
echo Please Confirm Username...
echo.
set /p confirm=Username:
if '%username%' == '%confirm%' goto User1
goto User
:User1
echo.
echo Please Input User Full Name...
echo.
set /p fullname=Full Name:
echo.
echo Please Input User Description...
echo.
set /p description=Description:
pause
echo Creating %username%...
net user %username% * /add /active:yes /fullname:"%fullname%" /comment:"%description%" /passwordchg:no /expires:never
wmic useraccount where "Name='%username%'" set PasswordExpires=FALSE

Update a batch file from another batch file

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 . . .

Need Assistance in creating a password/username system with batch

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. :)

Resources