I need to get a value in a registry key and store in a variable using a batch file.
I wrote a basic command line to exemplify my logic (using echo instead of setting a variable):
for /f "tokens=3 delims= " %%a in ('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "LastUsedUsername" ^|findstr /ri "REG_SZ"') do echo=%%a
I expect the username to be printed in the screen, but it doesn't happen.
I am sure the Registry value "LastUsedUsername" is not empty, it really has data. Also, the delimiter is a tab, not spaces.
EDIT
If I just type
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "LastUsedUsername"
... it returns:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
LastUsedUsername REG_SZ Administrador
This code
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "LastUsedUsername" ^| findstr /ri "REG_SZ"
... returns:
LastUsedUsername REG_SZ Administrador
Then, when I use the for command, I just get no output from echo.
reg query
the output uses spaces not tab, as @DaveO v2 agrees. Parsing with delims=(tab) doesn't work, parsing with the default does.