windows 强制 .NET 应用程序以 32 位运行的环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/619155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:07:18  来源:igfitidea点击:

Environment variable to force .NET applications to run as 32bit

.netwindows64-bitenvironment-variables

提问by fuzzyman

I've been told there is an environment variable you can set to force .NET applications to run as 32bit applications on x64 versions of Windows. Do you know what it is, or know of a reference on it? I'm afraid my google-fu has failed me today (or it doesn't exist).

有人告诉我,您可以设置一个环境变量来强制 .NET 应用程序在 x64 版本的 Windows 上作为 32 位应用程序运行。你知道它是什么,或者知道它的参考资料吗?恐怕我的 google-fu 今天失败了(或者它不存在)。

I'm using Resolver One (a .NET spreadsheet) and want to access some 32bit only functionality without modifying the executable. If I can configure this from an environment variable then I can access 32bit functionality when needed but also run as a 64bit app when needed.

我正在使用 Resolver One(一个 .NET 电子表格)并希望在不修改可执行文件的情况下访问某些仅限 32 位的功能。如果我可以从环境变量中配置它,那么我可以在需要时访问 32 位功能,但也可以在需要时作为 64 位应用程序运行。

(NOTE: effectively I want to be able to switch whether an application runs as 32bit or 64bit at launch time instead of forcing it at compile time.)

(注意:实际上我希望能够在启动时切换应用程序以 32 位还是 64 位运行,而不是在编译时强制它。)

Thanks

谢谢

采纳答案by fuzzyman

I've had an answer from Dino Veihland (Microsoft IronPython developer). I haven't had time to test it yet...

我从 Dino Veihland(Microsoft IronPython 开发人员)那里得到了答案。我还没来得及测试...

It's COMPLUS_ENABLE_64BIT. I think setting it to 0 disables 64-bit.

它是 COMPLUS_ENABLE_64BIT。我认为将其设置为 0 会禁用 64 位。

You should be able to set it as an env var or add a value to HKLM\Software\Microsoft\.NETFramework with the name "Enable_64Bit", the type REG_DWORD and the value 0 to set it globally (this is how all the COMPlus_* vars work). This one might be special enough (it has to run before the process is created) that it has to be set in the reg key but I'm not entirely certain.

您应该能够将其设置为 env var 或向 HKLM\Software\Microsoft\.NETFramework 添加一个名为“Enable_64Bit”的值,类型为 REG_DWORD 和值 0 以全局设置它(这就是所有 COMPlus_*变量工作)。这个可能很特别(它必须在创建进程之前运行),它必须在 reg 键中设置,但我并不完全确定。

回答by Eric Petroelje

How about this link

这个链接怎么样

Not quite an environment variable, but just use the CoreFlags tool to switch back and forth.

不是一个环境变量,只是使用 CoreFlags 工具来回切换。

To switch to 32 bit:

要切换到 32 位:

CorFlags.exe TheApp.exe /32BIT+ 

To go back to 64 bit:

回到 64 位:

CorFlags.exe TheApp.exe /32BIT- 

回答by eglasius

回答by Brady Moritz

Im going to try this one soon - basically an exe wrapper that runs in 32 bit, then launches your targeted app from it. the 32 bit mode of the parent should force an AnyCPU compiled binary to run in 32 bit. see http://lostechies.com/gabrielschenker/2009/10/21/force-net-application-to-run-in-32bit-process-on-64bit-os/

我很快就会尝试这个 - 基本上是一个以 32 位运行的 exe 包装器,然后从中启动您的目标应用程序。父级的 32 位模式应该强制 AnyCPU 编译的二进制文件以 32 位运行。见http://lostechies.com/gabrielschenker/2009/10/21/force-net-application-to-run-in-32bit-process-on-64bit-os/