7
3
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.
What makes you sure the delimiter is tab? On my Win8.1 it's several spaces (looks like 4). – dave_thompson_085 – 2015-11-04T02:26:18.693
I typed "tab" in notepad. When I copy from notepad to here, the tab turns into these 4 spaces. – John – 2015-11-04T11:22:45.877
John: I mean on 8.1 when I do the
reg query
the output uses spaces not tab, as @DaveO v2 agrees. Parsing with delims=(tab) doesn't work, parsing with the default does. – dave_thompson_085 – 2015-11-05T16:21:30.207Sorry, I didn't get it. You and he are correct. I have an very old .bat script that uses tab as delimiter and it still works even on my Windows 8. Thinking about why it works and my script doesn't, I guess it's because the reg.exe (used in the old script) is an older version than Windows 8 native reg.exe. Thank you! – John – 2015-11-08T18:15:47.437