3

I have made a .reg file where I set certain registry values. but I need to have a printout of situation before and after.

So how can I easily read out all reg values (within this regfile)? And is it possible to fill in a registry value with %computer name% so that this registry will use the current computer name for example:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\WinLogon
"AutoAdminLogon"="REG_SZ:1"
"AutoLogonDomain"="REG_SZ:%ComputerName%"
"AutoLogonUser"="REG_SZ:User1"
"DefaultDomain"="REG_SZ:%ComputerName%"
"DefaultDomainName"="REG_SZ:%ComputerName%"
"DefaultUsername"="REG_SZ:User1"
clhy
  • 6,283
  • 8
  • 34
  • 66
Joep
  • 55
  • 6

2 Answers2

1

this worked for me: REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon >nul if %errorlevel% equ 0 echo key AutoAdminLogon exists || key AutoAdminLogon does not exist but still need the add function when it not exists to create the registrykey...

Joep
  • 55
  • 6
0

I'm by no means an expert but I hope I can help you out :)
I've thrown together a batch file with the help of various sites and answers from here.
This script reads the current registry values and prints them out to the console.
Then it adds the registry values with your desired values and prints them again so you can see the changes.
I am pretty sure that you can optimize it a lot but it should be enough for giving you a start.

@echo OFF
echo "Current values..."
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonDomain
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonUser
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomain
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUsername

echo "Now performing the changes..."
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v AutoAdminLogon /t REG_SZ /d 1

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v AutoLogonDomain /t REG_SZ /d %ComputerName%

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v AutoLogonUser /t REG_SZ /d User1

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v DefaultDomain /t REG_SZ /d %ComputerName%

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v DefaultDomainName /t REG_SZ /d %ComputerName%

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" /f /v DefaultUsername /t REG_SZ /d User1

echo "Printing out new values..."
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonDomain
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonUser
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomain
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUsername
pause

Copy it to a text file and change the file ending to .cmd
The following sites helped me to create it - you might want to have a look at it:
How to find the PCs name in a batch script?
Adding key to registry
Reading NT's Registry with REG Query Is it possible to modify a registry entry via a .bat/.cmd script?

benjamin
  • 473
  • 1
  • 5
  • 13
  • I was planning to do this with powershell but this also works! thnks ! – Joep May 25 '16 at 10:03
  • How to do it with PS: function Get-RegistryValue { param ( [Parameter(Mandatory = $true)] $RegistryKey ) $key = Get-Item -Path "Registry::$RegistryKey" $key.GetValueNames() | ForEach-Object { $name = $_ $rv = 1 | Select-Object -Property Name, Type, Value $rv.Name = $name $rv.Type = $key.GetValueKind($name) $rv.Value = $key.GetValue($name) $rv } } Get-RegistryValue 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' – Joep May 25 '16 at 10:32
  • What can i do when registry does not exists ? Can I 'print' which one gives error or can I let it add by batchfile – Joep May 25 '16 at 13:35
  • Can you please rephrase/add more information? I don't quite understand – benjamin May 25 '16 at 13:52
  • REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon >nul if %errorlevel% equ 0 echo ("Key AutoAdminLogon Exists") else ("Key does not exists") I tried this, so I know when the key doesn't exists but i doesn't work ... also I would like to add the registry key if it doesn't exists – Joep May 25 '16 at 14:02
  • Ok I understand - I'll try to figure something out when I have time :) – benjamin May 25 '16 at 14:11