spetzz
spetzz

Reputation: 679

What will 'Environment.SpecialFolder.SystemX86' return on 32 bit Windows OS?

I have an application which should spawn a 32 bit CMD process.

bool is64BitOS = Environment.Is64BitOperatingSystem;
Environment.SpecialFolder systemFolder = is64BitOS ? Environment.SpecialFolder.SystemX86 : 
Environment.SpecialFolder.System;
processName = Path.Combine(Environment.GetFolderPath(systemFolder),"cmd.exe");

I was wondering whether I need to check for OS bitness to handle the differences between 64 bit and 32 bit Windows CMD path
or
Will 'Environment.SpecialFolder.SystemX86' handle the differences and I do not have to worry about it?

PS: My application is compiled with 'AnyCPU' target platform

Upvotes: 2

Views: 986

Answers (1)

Jeroen Mostert
Jeroen Mostert

Reputation: 28759

On a 32-bit system, you'll get back the same value as you get for SpecialFolder.System, so no, this isn't necessary. You can use SpecialFolder.SystemX86 to unambiguously get the system folder containing 32-bit binaries.

Source: Environment.GetFolderPath delegates to SHGetFolderPath, with SpecialFolder.SystemX86 mapping to CSIDL_SYSTEMX86, which is documented here to map to %windir%\system32 on 32-bit systems. This value was introduced in Windows 2000, so unless you're planning to run on a very old and unsupported version of Windows (with an equally ancient version of .NET) there's no need to check.

Note that the results depend only on the bitness of your OS, not the bitness of your process; 32-bit and 64-bit processes will get back the same values (but, of course, file system redirection means 32-bit processes usually access SysWOW64 under the hood when they access System32).

Upvotes: 3

Related Questions