Click here to Skip to main content
15,908,013 members
Home / Discussions / C#
   

C#

 
AnswerRe: Disposing of values in foreach loop Pin
Luc Pattyn14-Oct-11 15:12
sitebuilderLuc Pattyn14-Oct-11 15:12 
GeneralRe: Disposing of values in foreach loop Pin
PIEBALDconsult14-Oct-11 16:43
mvePIEBALDconsult14-Oct-11 16:43 
AnswerRe: Disposing of values in foreach loop Pin
Luc Pattyn14-Oct-11 16:58
sitebuilderLuc Pattyn14-Oct-11 16:58 
QuestionNeed help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk314-Oct-11 7:01
turbosupramk314-Oct-11 7:01 
AnswerRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
André Kraak14-Oct-11 8:55
André Kraak14-Oct-11 8:55 
GeneralRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk317-Oct-11 8:15
turbosupramk317-Oct-11 8:15 
GeneralRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk318-Oct-11 6:25
turbosupramk318-Oct-11 6:25 
GeneralRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk318-Oct-11 11:54
turbosupramk318-Oct-11 11:54 
Here is the closest I could get, I cannot figure out how to convert "int ret" to a "UIntPtr inHive", and so I am not able to get any further or test.

What do you think?


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Forms;

namespace Updator
{
    class _64to32bit3
    {
        public enum RegSAM
        {
            QueryValue = 0x0001,
            SetValue = 0x0002,
            CreateSubKey = 0x0004,
            EnumerateSubKeys = 0x0008,
            Notify = 0x0010,
            CreateLink = 0x0020,
            WOW64_32Key = 0x0200,
            WOW64_64Key = 0x0100,
            WOW64_Res = 0x0300,
            Read = 0x00020019,
            Write = 0x00020006,
            Execute = 0x00020019,
            AllAccess = 0x000f003f
        }

        [DllImport("Advapi32.dll")]
        static extern uint RegOpenKeyEx(
            UIntPtr hKey,
            string lpSubKey,
            uint ulOptions,
            int samDesired,
            out int phkResult);

        [DllImport("Advapi32.dll")]
        static extern uint RegCloseKey(int hKey);

        [DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx")]
        public static extern int RegQueryValueEx(
            int hKey,
            string lpValueName,
            int lpReserved,
            ref RegistryValueKind lpType,
            StringBuilder lpData,
            ref uint lpcbData);

        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
        private static extern int RegQueryValueEx(
            int hKey,
            string lpValueName,
            int lpReserved,
            ref RegistryValueKind lpType,
            [Out] byte[] lpData,
            ref uint lpcbData);

        [DllImport("advapi32")]
        static extern int RegConnectRegistry(string machine, UIntPtr hKey, out
        IntPtr pRemKey);
        [DllImport("advapi32")]
        static extern int RegCloseKey(IntPtr hKey);
        [DllImport("advapi32")]
        static extern int RegSaveKey(IntPtr hKey, string fileout, IntPtr
        secdesc);


        const uint HKEY_CLASSES_ROOT = 0x80000000;
        const uint HKEY_CURRENT_USER = 0x80000001;
        const uint HKEY_LOCAL_MACHINE = 0x80000002;

        public static void reg64reader()
        {
            UIntPtr key = new UIntPtr(HKEY_LOCAL_MACHINE);
            IntPtr remKey;
            int ret = RegConnectRegistry("SERVERNAME", key, out remKey);
            GetRegKey64(ret, @"SOFTWARE\Microsoft\DirectX", RegSAM.WOW64_64Key, "Version");
            MessageBox.Show(GetRegKey64(ret, @"SOFTWARE\Microsoft\DirectX", RegSAM.WOW64_64Key, "Version").ToString());
            RegCloseKey(remKey);        
        }

        static public string GetRegKey64(UIntPtr inHive, String inKeyName, RegSAM in32or64key, String inPropertyName)
        {
            int hkey = 0;

            try
            {
                uint lResult = RegOpenKeyEx(inHive, inKeyName, 0, (int)RegSAM.QueryValue | (int)in32or64key, out hkey);
                if (0 != lResult) return null;
                RegistryValueKind lpType = 0;
                uint lpcbData = 1024;
                StringBuilder strBuffer = new StringBuilder(1024);
                RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, strBuffer, ref lpcbData);
                string value = strBuffer.ToString();
                return value;
            }
            finally
            {
                if (0 != hkey) RegCloseKey(hkey);
            }
        }
    }
}

GeneralRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk318-Oct-11 12:49
turbosupramk318-Oct-11 12:49 
SuggestionRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
André Kraak19-Oct-11 9:19
André Kraak19-Oct-11 9:19 
GeneralRe: Need help reading 64bit registry keys from a 32bit application, remotely Pin
turbosupramk319-Oct-11 12:24
turbosupramk319-Oct-11 12:24 
QuestionCodeParser for C# source code Pin
Bernhard Hiller14-Oct-11 3:27
Bernhard Hiller14-Oct-11 3:27 
AnswerRe: CodeParser for C# source code Pin
PIEBALDconsult14-Oct-11 4:34
mvePIEBALDconsult14-Oct-11 4:34 
GeneralRe: CodeParser for C# source code Pin
Bernhard Hiller16-Oct-11 20:50
Bernhard Hiller16-Oct-11 20:50 
Questionto create a video file from a list of bitmap picture files in C sharp Pin
Member 823309513-Oct-11 17:34
Member 823309513-Oct-11 17:34 
AnswerRe: to create a video file from a list of bitmap picture files in C sharp Pin
AditSheth13-Oct-11 18:58
AditSheth13-Oct-11 18:58 
QuestionWindows 7: Getting The 'preview' file icon Pin
Michael Handschuh13-Oct-11 13:11
Michael Handschuh13-Oct-11 13:11 
AnswerRe: Windows 7: Getting The 'preview' file icon Pin
Ravi Bhavnani13-Oct-11 16:17
professionalRavi Bhavnani13-Oct-11 16:17 
GeneralRe: Windows 7: Getting The 'preview' file icon Pin
Michael Handschuh13-Oct-11 21:12
Michael Handschuh13-Oct-11 21:12 
GeneralRe: Windows 7: Getting The 'preview' file icon Pin
Ravi Bhavnani14-Oct-11 1:40
professionalRavi Bhavnani14-Oct-11 1:40 
QuestionVery basic OOP question Pin
SFORavi13-Oct-11 12:40
SFORavi13-Oct-11 12:40 
AnswerRe: Very basic OOP question Pin
PIEBALDconsult13-Oct-11 12:43
mvePIEBALDconsult13-Oct-11 12:43 
AnswerRe: Very basic OOP question Pin
Michael Handschuh13-Oct-11 13:14
Michael Handschuh13-Oct-11 13:14 
GeneralRe: Very basic OOP question Pin
SFORavi13-Oct-11 13:36
SFORavi13-Oct-11 13:36 
GeneralRe: Very basic OOP question Pin
Michael Handschuh13-Oct-11 13:51
Michael Handschuh13-Oct-11 13:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.