응용프로그램의 플랫폼x86 으로 설정하였다. 이 응용프로그램은 x86 환경에선 당연히 x86 응용프로그램으로 동작하고, x64 환경에선 x86 으로 WOW로 동작한다. 응용프로그램에서 다음과 같이 레지스트리 키를 생성한다면?!


string portRegPath = "Software\\Yuk\\MyApp\\RegDemo";

key = Registry.LocalMachine.OpenSubKey(portRegPath, true);

if (key == null)

{

      key = Registry.LocalMachine.CreateSubKey(portRegPath);

}


x86 플랫폼의 응용프로그램이 x86 응용프로그램으로 실행 될 경우 LocalMachiine 의 Software\\Yuk\\MyApp\\RegDemo 에 기록. x64 WOW 로 실행 될 경우 LocalMachine 의 Software\\Wow6432Node\\Yuk\\MyApp\\RegDemo 에 기록.


즉, WOW로 동작하는 응용프로그램을 위한 레지스트리가 따로 존재한다.



또한 CreateSubKey 에서 x86 레지스트리 경로를 사용하여 기록해도, x64에선 자동으로 Wow6432Node 레지스트리 경로에 기록된다. (레지스트리를 읽을 때도 동일하게 적용됨.)

*) x86 플랫폼으로 빌드된 응용프로그램일 경우만 그러하고, Any CPU, Mixed Ploatforms 로 빌드된 응용프로그램은 레지스트리 경로를 각각 직접 지정해줘야 한다.


직접적으로 WOW64 레지스트리 경로를 얻어야 할 경우, 다음 코드를 참조


public RegistryKey GetSoftwareRoot()

{

    var path = 8 == IntPtr.Size ? @"Software\Wow6432Node" : @"Software";

    return Registry.CurrentUser.OpenSubKey(path);

}


IntPtr 은 포인터나 핸들을 나타내는 데 사용되는 플랫폼별 형식으로 IntPtr.Size 값으로 x86 에선 4, x64 에선 8 값을 갖는다.




System.Environment.Is64BitOperationSystem

.NET Framework 4.0 이상 환경에서 개발한다면 Environment.Is64BitOperationSystem 프로퍼티를 이용하면 더 직관적으로 코딩할 수 있다. Environment.Is64BitOperaionSystem 프로퍼티는 현재 운영체제가 64비트 운영체제인지 확인해 준다.

RegistryKey registryKey; 
if (Environment.Is64BitOperatingSystem == true) 
{ 
    registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); 
} 
else 
{ 
    registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32); 
} 



참조

How to open a WOW64 registry key from a 64-bit .NET application - stackoverflow

Checking if the Current Process is 64-bit - blackwasp

Checking if the Operating System is 64-bit - blackwasp


@

Posted by six605
,