0

HKU

\\<host>\HKU\<SID>\Software\Microsoft\Windows\CurrentVersion\Run /s

Example:

for /f  "delims=\ tokens=2,*" %t in ('reg query HKU') do reg query HKU\%t         \Software\Microsoft\Windows\CurrentVersion\Run /s

HKLM

reg query \\<host>\HKLM\Software\Microsoft\Windows\CurrentVersion\Run /s

Example:

FOR /F %i in (hosts.txt) DO @echo [+] %i && 
@reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run /s 2>NUL > output.txt && 
FOR /F %n in (strings.txt) DO @type output.txt | findstr %n > NUL && 
echo [!] %n was found on %i!

Here are some examples that we have came up with at the office. But trying to figure out how to add in a psexec command to allow for us to query remote computers on the network.

So it would read the hosts from the hosts.txt file along with the strings from the strings.txt and possible add in a variable to change out the different registry keys. Then output it all into one text file.

Do you think this is too much to try in a batch file? What about a powershell script? Thanks

badbiddy
  • 11
  • 7

2 Answers2

1

To query remote registry keys with PowerShell use OpenRemoteBaseKey:

[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', 'computer-name')

The first parameter is the hive name, a list of which can be found here. The second is the name of the computer to connect to.

This will return a Microsoft.Win32.RegistryKey object which you can use to list sub keys and read their values.

Here is an example of reading the run key values:

$path = "Software\Microsoft\Windows\CurrentVersion\Run"
$key = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', 'computer-name')
$subkey = $key.OpenSubKey($path)
$subkey.GetValueNames() | ForEach-Object {
    '{0} : {1}' -f $_, $subkey.GetValue($_)
}
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
  • +1 I think it's worth mentioning that the `RemoteRegistry` service must be running on the remote host, and IIRC admin privileges are required for accessing it. – Ansgar Wiechers May 26 '13 at 08:35
0

You can also try the PSRemoteRegistry module:

 Get-RegValue -Hive LocalMachine -Key Software\Microsoft\Windows\CurrentVersion\Run -ComputerName server1
Shay Levy
  • 121,444
  • 32
  • 184
  • 206