Environment variable to force .NET applications to

2019-03-11 02:31发布

问题:

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).

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.

(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.)

Thanks

回答1:

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

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

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.



回答2:

How about this link

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

To switch to 32 bit:

CorFlags.exe TheApp.exe /32BIT+ 

To go back to 64 bit:

CorFlags.exe TheApp.exe /32BIT- 


回答3:

Check this: http://www.hanselman.com/blog/BackToBasics32bitAnd64bitConfusionAroundX86AndX64AndTheNETFrameworkAndCLR.aspx

target platform in project property dialog btw.



回答4:

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/