Reputation: 99
So I have a "set /p" line in my batch code, but no matter what I seem to do it always returns blank.
My code:
@echo off
IF NOT "%1" == "admin" (
ECHO 'Not admin'
Pushd "%~dp0"
copy %0 C:\
runas /user:administrator "C:\%~n0.bat admin %COMPUTERNAME%"
)
IF "%1" == "admin" (
set /p user= User initials:
ECHO Test: %user%
wmic computersystem where caption='%2' call rename 'GLOS-%user%01'
net localgroup administratorer %user% /add
manage-bde -off C:
pause
start /b "" cmd /c del "%~f0"&exit /b
)
pause
Anyone having any clue as to why this happens?
Thanks in advance!
Upvotes: 2
Views: 1472
Reputation: 6032
You have to add this at the beginning of your script (e.g. right below @eho off
):
SETLOCAL EnableDelayedExpansion
and further you have to surround user with !...! instead of %...%:
ECHO Test: !user!
That's it. For more information check this website
Upvotes: 4