Not quite, CDMTJX. There are 2 problems with the alternative you posted.
- Previous values for uname are not cleared. Running this twice WILL see the previous value
- The logic is backwards.
This will work as you intended:
@ECHO OFF
set uname=
SET /P uname="Please enter your name: "
IF "%uname%"=="" (
ECHO error ...
) ELSE (
ECHO Hello %uname%...
)