ホームページ データベース mysql チュートリアル Accessing 64 bit registry from a 32 bit process

Accessing 64 bit registry from a 32 bit process

Jun 07, 2016 pm 03:49 PM
bit from pr registry

As you may know, Windows is virtualizing some parts of the registry under 64 bit. So if you try to open, for example, this key : “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90″, from a 32 bit C# application running on a 6

As you may know, Windows is virtualizing some parts of the registry under 64 bit.

So if you try to open, for example, this key : “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90″, from a 32 bit C# application running on a 64 bit system, you will be redirected to : “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\90″

Why ? Because Windows uses the Wow6432Node registry entry to present a separate view of HKEY_LOCAL_MACHINE\SOFTWARE for 32 bit applications that runs on a 64 bit systems.

If you want to explicitly open the 64 bit view of the registry, here is what you have to perform :

You are using VS 2010 and version 4.x of the .NET framework

It’s really simple, all you need to do is, instead of doing :

//Will redirect you to the 32 bit view

RegistryKey sqlsrvKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\90");

do the following :

RegistryKey localMachineX64View = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

RegistryKey sqlsrvKey = localMachineX64View.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\90");


Prior versions of the .NET framework

For the prior versions of the framework, we have to use P/Invoke and call the function RegOpenKeyExW with parameter KEY_WOW64_64KEY

enum RegWow64Options

{

    None = 0,

    KEY_WOW64_64KEY = 0x0100,

    KEY_WOW64_32KEY = 0x0200

}

 

enum RegistryRights

{

    ReadKey = 131097,

    WriteKey = 131078

}

 

/// <summary></summary>

/// Open a registry key using the Wow64 node instead of the default 32-bit node.

///

/// <param name="parentKey">Parent key to the key to be opened.

/// <param name="subKeyName">Name of the key to be opened

/// <param name="writable">Whether or not this key is writable

/// <param name="options">32-bit node or 64-bit node

/// <returns></returns>

static RegistryKey _openSubKey(RegistryKey parentKey, string subKeyName, bool writable, RegWow64Options options)

{

    //Sanity check

    if (parentKey == null || _getRegistryKeyHandle(parentKey) == IntPtr.Zero)

    {

        return null;

    }

 

    //Set rights

    int rights = (int)RegistryRights.ReadKey;

    if (writable)

        rights = (int)RegistryRights.WriteKey;

 

    //Call the native function >.

    int subKeyHandle, result = RegOpenKeyEx(_getRegistryKeyHandle(parentKey), subKeyName, 0, rights | (int)options, out subKeyHandle);

 

    //If we errored, return null

    if (result != 0)

    {

        return null;

    }

 

    //Get the key represented by the pointer returned by RegOpenKeyEx

    RegistryKey subKey = _pointerToRegistryKey((IntPtr)subKeyHandle, writable, false);

    return subKey;

}

 

/// <summary></summary>

/// Get a pointer to a registry key.

///

/// <param name="registryKey">Registry key to obtain the pointer of.

/// <returns>Pointer to the given registry key.</returns>

static IntPtr _getRegistryKeyHandle(RegistryKey registryKey)

{

    //Get the type of the RegistryKey

    Type registryKeyType = typeof(RegistryKey);

    //Get the FieldInfo of the 'hkey' member of RegistryKey

    System.Reflection.FieldInfo fieldInfo =

    registryKeyType.GetField("hkey", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

 

    //Get the handle held by hkey

    SafeHandle handle = (SafeHandle)fieldInfo.GetValue(registryKey);

    //Get the unsafe handle

    IntPtr dangerousHandle = handle.DangerousGetHandle();

    return dangerousHandle;

}

 

/// <summary></summary>

/// Get a registry key from a pointer.

///

/// <param name="hKey">Pointer to the registry key

/// <param name="writable">Whether or not the key is writable.

/// <param name="ownsHandle">Whether or not we own the handle.

/// <returns>Registry key pointed to by the given pointer.</returns>

static RegistryKey _pointerToRegistryKey(IntPtr hKey, bool writable, bool ownsHandle)

{

    //Get the BindingFlags for private contructors

    System.Reflection.BindingFlags privateConstructors = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;

    //Get the Type for the SafeRegistryHandle

    Type safeRegistryHandleType = typeof(Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid).Assembly.GetType("Microsoft.Win32.SafeHandles.SafeRegistryHandle");

    //Get the array of types matching the args of the ctor we want

    Type[] safeRegistryHandleCtorTypes = new Type[] { typeof(IntPtr), typeof(bool) };

    //Get the constructorinfo for our object

    System.Reflection.ConstructorInfo safeRegistryHandleCtorInfo = safeRegistryHandleType.GetConstructor(

    privateConstructors, null, safeRegistryHandleCtorTypes, null);

    //Invoke the constructor, getting us a SafeRegistryHandle

    Object safeHandle = safeRegistryHandleCtorInfo.Invoke(new Object[] { hKey, ownsHandle });

 

    //Get the type of a RegistryKey

    Type registryKeyType = typeof(RegistryKey);

    //Get the array of types matching the args of the ctor we want

    Type[] registryKeyConstructorTypes = new Type[] { safeRegistryHandleType, typeof(bool) };

    //Get the constructorinfo for our object

    System.Reflection.ConstructorInfo registryKeyCtorInfo = registryKeyType.GetConstructor(

    privateConstructors, null, registryKeyConstructorTypes, null);

    //Invoke the constructor, getting us a RegistryKey

    RegistryKey resultKey = (RegistryKey)registryKeyCtorInfo.Invoke(new Object[] { safeHandle, writable });

    //return the resulting key

    return resultKey;

}

 

[DllImport("advapi32.dll", CharSet = CharSet.Auto)]

public static extern int RegOpenKeyEx(IntPtr hKey, string subKey, int ulOptions, int samDesired, out int phkResult);


Then we can open our registry key like this :

RegistryKey sqlsrvKey = _openSubKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Microsoft SQL Server\90", false, RegWow64Options.KEY_WOW64_64KEY);

As you can see, the framework 4 make our life easier.


Referenced from: http://dotnetgalactics.wordpress.com/2010/05/10/accessing-64-bit-registry-from-a-32-bit-process/

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

PRの正式名称は何ですか? PRの正式名称は何ですか? Aug 22, 2022 pm 03:53 PM

PRの正式名称は「Adobe Premiere Pro」で、PRはAdobe社が開発した動画編集ソフトで、互換性が良く、Adobe社が発売する他のソフトと連携することができ、広告制作やテレビ番組の制作などで広く使われています。

pr にオーディオトラックがあるのに音が出ない場合の問題を解決する方法 pr にオーディオトラックがあるのに音が出ない場合の問題を解決する方法 Jun 26, 2023 am 11:07 AM

PR にはオーディオ トラックがありますが、サウンドがありません 解決策: 1. PR アプリケーションで、素材をタイムラインにドラッグします; 2. 編集メニューで環境設定を開きます; 3. 環境設定ウィンドウで、オーディオ ハードウェアの項目バーを開き、デフォルトの出力オプション ボックスを見つけます; 4. オプション ボックスで、スピーカー オプションを見つけて [OK] ボタンをクリックします; 5. PR アプリケーションに戻り、ビデオ プレビュー ウィンドウで再生すると、サウンドがブロードキャストされます。

1 ビットは何バイトに相当します 1 ビットは何バイトに相当します Mar 09, 2023 pm 03:11 PM

1 ビットは 1 バイトの 8 分の 1 に相当します。 2 進数体系では、0 または 1 がそれ​​ぞれ 1 ビット (bit) であり、ビットはデータ記憶の最小単位であり、8 ビット (bit、略して b) ごとに 1 バイト (Byte) が構成されます。バイト) = 8 ビット」。ほとんどのコンピュータ システムでは、バイトは 8 ビット (ビット) 長のデータ単位であり、文字、数字、またはその他の文字を表すためにバイトが使用されます。

pr ファイルの圧縮タイプがサポートされていない場合はどうすればよいですか? pr ファイルの圧縮タイプがサポートされていない場合はどうすればよいですか? Mar 23, 2023 pm 03:12 PM

PR ファイルの圧縮タイプがサポートされていない理由と解決策: 1. PR の合理化バージョンにより、多くのビデオ エンコーダが合理化されました。Premiere のフル バージョンを再インストールして使用してください。2. 不規則なビデオ エンコーディングが原因で、フォーマット ファクトリを使用して変換できます。ビデオを WMV 形式に変換します。

PR でビデオをコンパイルするときにエラーが発生した場合の対処方法 PR でビデオをコンパイルするときにエラーが発生した場合の対処方法 Mar 22, 2023 pm 01:59 PM

PR でビデオをコンパイルするときのエラーの解決策: 1. コンピューターで Premiere ポスト編集ソフトウェアを開き、プロジェクト設定の右側のメニュー バーで [一般] を選択します; 2. Premiere の一般設定ウィンドウに入り、 「Mercury のみのプレイバック エンジン ソフトウェア」を選択します。 3. PR でビデオをコンパイルする際のエラーを解決するには、「確認」をクリックします。

PR 字幕はどのようにして一字一句表示されるのでしょうか? PR 字幕はどのようにして一字一句表示されるのでしょうか? Aug 11, 2023 am 10:04 AM

PR 字幕を逐語的に表示する方法: 1. 字幕トラックを作成する; 2. 字幕テキストを追加する; 3. 長さを調整する; 4. 逐語的効果を表示する; 5. アニメーション効果を調整する; 6. 字幕の位置と透明度を調整する; 7 . ビデオをプレビューしてエクスポートします。

PR 外部スライドツールとは何ですか? PR 外部スライドツールとは何ですか? Jun 30, 2023 am 11:47 AM

PR外部スライドツールは、広報担当者のPR業務を効率化するために使用するツールで、具体的な機能としては、1.広報担当者のメディア監視・分析の支援、2.広報担当者の世論監視・分析の支援、3.広報担当者の支援などがあります。広報担当者 担当者がメディア関係管理を実施する; 4. 広報担当者がプレスリリースを作成および発行するのを支援する; 5. 広報担当者がデータ分析とレポート作成を実行するのを支援する。

WIN10でレジストリプロセスを閉じる操作手順 WIN10でレジストリプロセスを閉じる操作手順 Mar 27, 2024 pm 05:51 PM

1. キーボードの [Win+R] ショートカット キーの組み合わせを押したままにして、[ファイル名を指定して実行] ダイアログ コマンド ウィンドウを開き、[services.msc] コマンドを入力して、[OK] をクリックします。 2. サービス インターフェイスを開いた後、[RemoteRegistry] オプションを見つけ、左ボタンでダブルクリックしてプロパティ ダイアログ ウィンドウを開きます。 3. 表示される[RemoteRegistryのプロパティ]ダイアログウィンドウで、スタートアップの種類オプションで[無​​効]オプションを選択し、[適用]--[停止]--[OK]ボタンをクリックして設定を保存します。

See all articles