You could rule out the possibility that another connection is beating you to it by running the startup and login commands in the same command line script. This will ensure you're first in line.
@echo off
REM Stop SQL Server Service (Replace MSSQLSERVER with your instance name if it's not the default)
net stop MSSQLSERVER
REM Start SQL Server in single-user mode and check if the command is successful
net start MSSQLSERVER /m"sqlcmd" && (
echo SQL Server started in single-user mode.
REM Immediately connect to SQL Server using sqlcmd
sqlcmd -S . -E
) || (
echo Failed to start SQL Server in single-user mode.
exit /b 1
)