Accessing 64 bit registry from a 32 bit process
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/

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

pr的全名為「Adobe Premiere Pro」;pr是由Adobe公司開發的影片編輯軟體,有著較好的相容性,並且可以與Adobe公司推出的其他軟體相互協作,廣泛應用於廣告製作和電視節目製作中。

pr有音軌但沒有聲音解決方法:1、在PR應用中,將素材拖入時間軸;2、在編輯選單中,開啟首選項;3、在首選項視窗中,開啟音訊硬體專案欄,找到預設輸出選項框;4、在選項框中,找到揚聲器選項,點選確定按鈕;5、回到PR應用程式中,在影片預覽視窗中,進行播放,就會有聲音播出。

1bit等於八分之一個位元組。二進制數係統中,每個0或1就是一個位元(bit),位元是資料儲存的最小單位;每8個位元(bit,簡寫為b)組成一個位元組(Byte),因此「1位元組( Byte)=8位元(bit)」。在多數的電腦系統中,一個位元組是一個8位元(bit)長的資料單位,大多數的計算機都用一個位元組表示一個字元、數字或其他字元。

pr檔案的壓縮類型不受支援的原因及解決方法:1、精簡版pr把許多視訊編碼器精簡掉了,重新安裝使用完整版Premiere;2、視訊編碼不規範導致的,可以透過格式工廠,將影片轉換成WMV格式即可。

pr編譯影片時出錯的解決方法:1、在電腦上開啟premiere後期剪輯軟體,然後在專案設定的右側選單列中,選擇「常規」;2、進入到premiere的常規設定窗口,選擇「僅Mercury Playback Engine軟體」;3.點選「確認」即可解決pr編譯影片時出錯問題。

pr字幕逐字出現的方法:1、創建字幕軌道;2、添加字幕文字;3、調整持續時間;4、逐字出現效果;5、調整動畫效果;6、調整字幕的位置和透明度;7、預覽和導出視頻。

1.按住鍵盤的【Win+R】快捷組合鍵,開啟【執行】對話指令窗口,輸入【services.msc】指令,點選【確定】;。 2.開啟服務介面後找到【RemoteRegistry】選項,並左鍵雙擊開啟其屬性對話方塊。 3.在開啟的【RemoteRegistry的屬性】對話方塊中,在啟動類型選項中選擇【停用】選項,再點選【套用】--【停止】--【確定】按鈕儲存設定即可。

pr是Public Relations的縮寫,是一種重要的組織管理工具,旨在透過建立和維護良好的關係來提高組織的聲譽和信任度。它需要透明度、真實性和一致性,同時需要與新媒體和社交媒體緊密結合。透過有效的pr實踐,組織可以獲得更廣泛的認可和支持,提高其競爭力和永續發展能力。
