Accessing 64 bit registry from a 32 bit process
Jun 07, 2016 pm 03:49 PMAs 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/

Outils d'IA chauds

Undress AI Tool
Images de déshabillage gratuites

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
échangez les visages dans n'importe quelle vidéo sans effort grace à notre outil d'échange de visage AI entièrement gratuit?!

Article chaud

Outils chauds

Bloc-notes++7.3.1
éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

PR a une piste audio mais pas de son Solution : 1. Dans l'application PR, faites glisser le matériel dans la timeline 2. Dans le menu d'édition, ouvrez les préférences 3. Dans la fenêtre des préférences, ouvrez la barre des éléments du matériel audio et recherchez la bo?te d'option de sortie par défaut?; 4. Dans la bo?te d'options, recherchez l'option du haut-parleur et cliquez sur le bouton OK?; 5. Revenez à l'application PR, lisez-la dans la fenêtre d'aper?u vidéo et le son sera diffusé.

Le nom complet de PR est ? Adobe Premiere Pro ? ; PR est un logiciel de montage vidéo développé par Adobe. Il a une bonne compatibilité et peut coopérer avec d'autres logiciels lancés par Adobe. Il est largement utilisé dans la production publicitaire et les programmes télévisés.

1 bit équivaut à un huitième d'octet. Dans le système de nombres binaires, chaque 0 ou 1 est un bit (bit), et un bit est la plus petite unité de stockage de données?; tous les 8 bits (bit, abrégé en b) constituent un octet (Byte), donc "1 octet ( Octet) = 8 bits ?. Dans la plupart des systèmes informatiques, un octet est une unité de données de 8 bits (bits). La plupart des ordinateurs utilisent un octet pour représenter un caractère, un nombre ou un autre caractère.

Raisons et solutions pour le type de compression non pris en charge des fichiers PR?: 1. La version simplifiée de PR a rationalisé de nombreux encodeurs vidéo. Réinstallez et utilisez la version complète de Premiere. 2. En raison d'un encodage vidéo irrégulier, vous pouvez utiliser l'usine de format pour convertir. la vidéo au format WMV.

Méthodes pour que les sous-titres apparaissent textuellement?: 1. Créez une piste de sous-titres?; 2. Ajoutez le texte des sous-titres?; 3. Ajustez la durée?; ; 7. Prévisualisez et exportez des vidéos.

Solution à l'erreur lors de la compilation d'une vidéo dans PR : 1. Ouvrez le logiciel de post-édition Premiere sur l'ordinateur, puis sélectionnez ? Général ? dans la barre de menu de droite des paramètres du projet. 2. Entrez dans la fenêtre des paramètres généraux de Premiere et ; sélectionnez "Mercure uniquement" Playback Engine Software"?; 3. Cliquez sur "Confirmer" pour résoudre l'erreur lors de la compilation de la vidéo dans PR.

L'outil coulissant externe des relations publiques est utilisé pour aider les praticiens des relations publiques à mieux effectuer leur travail de relations publiques. Ses fonctions spécifiques sont : 1. Aider les praticiens des relations publiques à effectuer la surveillance et l'analyse des médias ; Praticiens des relations publiques Les praticiens gèrent les relations avec les médias?; 4. Aider les praticiens des relations publiques à rédiger et à publier des communiqués de presse. 5. Aider les praticiens des relations publiques à effectuer l'analyse des données et la génération de rapports?;

PR, abréviation de Public Relations, est un outil de gestion organisationnelle important con?u pour améliorer la réputation et la confiance d'une organisation en établissant et en entretenant de bonnes relations. Cela nécessite transparence, authenticité et cohérence, tout en étant étroitement intégré aux nouveaux médias et aux médias sociaux. Grace à des pratiques de relations publiques efficaces, les organisations peuvent obtenir une reconnaissance et un soutien plus larges, améliorant ainsi leur compétitivité et leurs capacités de développement durable.
