Batch – Return Current User

email me

@echo off

for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set domainuser=%%c

for /f "TOKENS=1,2 DELIMS=\" %%a in ("%domainuser%") do set domain=%%a & set user=%%b

echo %user%
pause

 

 

tags: Windows current user, command line, MrNetTek