2

Im trying to read the below registry key on a 64 bit version of windows server 2008 r2 from a 32 bit windows 2008 using powershell, but the value comes as blank and does not return anyvalues.

can some help me on how can i read a 64 bit reg key from a 32 bit server ?

$line = "WIN-QENOBBC64B8"
$regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $line)
$ref = $regKey.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")
$ref
PowerShell
  • 1,991
  • 8
  • 35
  • 57

3 Answers3

3

From 32bit powershell, you access the 64bit registry by calling the 64bit version of reg.exe from the command line. The trick is in using the sysnative path instead of system32, which gets you out of the syswow64 sandbox and into the real 64 bit registry.

C:\Windows\SysNative\reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41
2

If you are running PowerShell on .NET 4 (look at the output of $PSVersionTable) then you can use the new RegistryView enumeration (and OpenRemoteBaseKey overload) with the [Microsoft.Win32.RegistryView]::Registry64 to be able to view the 64-bit registry.

Alternatively you could use PowerShell remoting since by default you will be connected to the 64-bit PowerShell endpoint on the remote machine e.g.:

$line = "WIN-QENOBBC64B8"
Invoke-Command -ComputerName $line {Get-Item 'HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL'}

Note that you may have to enable remoting on the remote server (can't remember if PowerShell remoting is enabled by default on servers). You can do this by running the following commands on the remote server in an elevated/admin PowerShell prompt:

Set-ExecutionPolicy RemoteSigned
Enable-PSRemoting
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
0

Try this as your last line if looking for values:

$ref.GetValueNames()

or if you are looking for keys:

$ref.GetSubKeyNames()
Raf
  • 9,681
  • 1
  • 29
  • 41
  • Run `$ref -eq $null`. If `false` then try `$ref | gm ` and investigate underlying properties and methods; if `true` then have a good weekend :) – Raf Aug 01 '14 at 15:52
  • The question is about accessing the 64-bit registry from a 32-bit process; it's unclear how your answer relates to that. – mklement0 Nov 10 '20 at 22:30