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

后端 未结 8 1194
北荒
北荒 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
                );
    
            }
        }
    }
    

提交回复
热议问题