0

So, I'm having an issue where I am trying to automate the process of setting up autoadminlogon in the registry for normal users using a Batch Script. My current issue is that I'm trying to make this process more streamlined by having the script either use the files name which would be the same as the username, or for it to use %USERNAME%. But every time I run the Batch Script in Administrator and use %USERNAME% it spits out the admin accounts username, and not the current users.

This is what the Script looks like

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d Test

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d Test

I'm doing roughly 30+ computers, so not having to either manually add all of the registry values, or having to create X amount of different Scripts would be preferred.

1 Answers1

1

You could run the batch file as your regular user and use PowerShell to elevate the batch file while passing the current username to the batch.

Something like:
powershell -command "Start-Process cmd -ArgumentList '/c cd /d %CD% && autologon.bat %USERNAME%' -Verb runas"

Then the batch file can be amended as such..

Set "UserName=%~1"
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %UserName%
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d Test

You probably saw @harrymc post about the batch file.

If you have network access to these machines, I highly suggest that you learn how to use WMI to do it remotely. It is actually pretty easy to do.