Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add to GPO Startup Script (Must run with SYSTEM privileges)
- ===========================================================
- @ECHO OFF
- SETLOCAL ENABLEDELAYEDEXPANSION
- REG QUERY "HKLM\<YourRegPath>" >NUL 2>&1 || (
- ECHO.
- ECHO Creating LastLoggedOnUser Registry Key...
- REG ADD "HKLM\<YourRegPath>" /v "LastLoggedOnUser" /f >NUL
- )
- ECHO.
- ECHO Setting permissions on LastLoggedOnUser Registry Key...
- SETACL -on "HKLM\<YourRegPath>" -ot reg -rec yes -actn setowner -ownr "n:Users" >NUL
- SETACL -on "HKLM\<YourRegPath>" -ot reg -rec yes -actn ace -ace "n:Users;p:full" >NUL
- Add to GPO Startup Script (Must run for everyone logging in, including Administrators)
- ======================================================================================
- @ECHO OFF
- SETLOCAL ENABLEDELAYEDEXPANSION
- FOR /F "skip=2 tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "CurrentVersion" 2^> NUL') DO (
- SET OSVer=%%A
- )
- ECHO.
- ECHO Updating LastLoggedOnUser...
- IF /i "%UserName%"=="Administrator" (
- FOR /F "skip=2 tokens=3" %%A IN ('REG QUERY "HKLM\<YourRegPath>" /v "LastLoggedOnUser" 2^> NUL') DO (
- SET var=%%A
- )
- IF "%OSVer:~0,2%"=="5." (
- REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" /d "!var!" /f >NUL
- )
- IF "%OSVer:~0,2%"=="6." (
- REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" /v "LastLoggedOnUser" /d "!var!" /f >NUL
- )
- ) ELSE (
- IF "%OSVer:~0,2%"=="5." (
- REG ADD "HKLM\<YourRegPath>" /v "LastLoggedOnUser" /d "%UserName%" /f >NUL
- )
- IF "%OSVer:~0,2%"=="6." (
- REG ADD "HKLM\<YourRegPath>" /v "LastLoggedOnUser" /d "%UserDomain%\%UserName%" /f >NUL
- )
- )
Add Comment
Please, Sign In to add comment