How to access the 64-bit registry from a 32-bit Powershell instance?

后端 未结 8 1200
北荒
北荒 2020-12-06 09:54

If you launch a 32-bit instance of Powershell (%SystemRoot%\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe), then the registry provider only sees the limited 32-bit part

相关标签:
8条回答
  • 2020-12-06 10:45

    A slight variation of the answer from Milan is to host powershell using the C# program as per Bart De Smet's blog. Although that blog entry focusses on compiling against .NET 4.0, you can compile the same against .NET 3.5 as well. The result is a binary that is a PowerShell host that can access 64bit registry entires when invoked from a 32-bit process:

    using System;
    using System.Management.Automation.Runspaces;
    using Microsoft.PowerShell;
    
    namespace PSHost
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                var config = RunspaceConfiguration.Create();
                ConsoleShell.Start(
                    config,
                    "Windows PowerShell - Compiled for ANY CPU",
                    "",
                    args
                );
    
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-06 10:46

    The easiest way is to use this shortcut: C:\Windows\sysnative which is equivalent to C:\Windows\System32 -- but the key difference is that the process is launched as a 64-bit process. Therefore, the easiest way to access the 64-bit registry from a 32-bit powershell is to call reg.exe via C:\Windows\sysnative For example:

    C:\Windows\sysnative\reg.exe QUERY HKLM\SOFTWARE\JavaSoft\JDK
    

    source: https://stackoverflow.com/a/25103599

    If, for some reason, you needed to access the 32-bit registry from a 64-bit command-line use C:\Windows\syswow64

    C:\Windows\syswow64\reg.exe QUERY HKLM\SOFTWARE\JavaSoft
    
    0 讨论(0)
提交回复
热议问题