Reputation: 689
I have developed a software, that requires current logged in user name, but during the installation, I provide the admin user( admin right user). my application fetches the admin user. is there any way to get the current user name/ details from the registry.
I tried to fetch the HKEY_CURRENT_USER, however, it returns the admin user profile.
Upvotes: 0
Views: 6114
Reputation: 724
I'm not exactly sure why you'd want to get this from the registry via batch file, but if you just want to get it in a batch file, just look at the %username%
environment variable. Alternatively if you want to get domain\machine information, check the output of whoami
. Lastly if you want a bit more information and want to parse it, you can use Query user
but that would be decidedly more messy.
C:\Users\myname>echo %username%
myname
Or
C:\Users\myname>whoami
domain\myname
Upvotes: 4
Reputation: 18857
I don't know if this what you want as to query the value of LastUsedUsername
?
@echo off
set "Winlogonkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
@for /f "tokens=3 skip=2 delims= " %%a in (
'Reg Query "%Winlogonkey%" /v LastUsedUsername'
) do (
Set "LastUsedUsername=%%a"
)
echo "%LastUsedUsername%"
pause
Upvotes: 0