Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
GeneralRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
Eddy Vluggen23-Mar-12 13:45
professionalEddy Vluggen23-Mar-12 13:45 
GeneralRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
turbosupramk323-Mar-12 18:33
turbosupramk323-Mar-12 18:33 
QuestionRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
Eddy Vluggen24-Mar-12 2:20
professionalEddy Vluggen24-Mar-12 2:20 
AnswerRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
turbosupramk324-Mar-12 15:14
turbosupramk324-Mar-12 15:14 
AnswerRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
turbosupramk326-Mar-12 6:04
turbosupramk326-Mar-12 6:04 
GeneralRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
turbosupramk326-Mar-12 4:58
turbosupramk326-Mar-12 4:58 
AnswerRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
Eddy Vluggen26-Mar-12 7:27
professionalEddy Vluggen26-Mar-12 7:27 
GeneralRe: Can read 64bit Reg_Sz, but not 64bit D_Word Pin
turbosupramk326-Mar-12 8:23
turbosupramk326-Mar-12 8:23 
Thanks for sparking some thought and putting me in the right direction.

Here is what I ended up doing (some constants and pin invokes are needed from the first post), you can then call the method and get the return value of a hex or dec number, the registry key in the first code section below will call a 64 bit key that is on every 2008 server and allow for testing with this from a 32 bit OS.

GetRegKey64DWord has the actual parsing code. This is an "unclean" version of the code, as I just got it working, hopefully I'll have a full class soon.

C#
private void button6_Click(object sender, EventArgs e) // Test
{
    string result = _64to32bit.reg64reader("[servername]", "HKEY_LOCAL_MACHINE", @"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate"); // 1250788789 or 4a8d85b5
    MessageBox.Show(result);
}




C#
public static string reg64reader(string serverName, string hive, string keyPath, string stringValue)
{
    uint hiveConst = HKEY_LOCAL_MACHINE;
    switch (hive)
    {
        case "hkcr":
            hiveConst = HKEY_CLASSES_ROOT;
            break;
        case "hkey_classes_root":
            hiveConst = HKEY_CLASSES_ROOT;
            break;
        case "HKCR":
            hiveConst = HKEY_CLASSES_ROOT;
            break;
        case "HKEY_CLASSES_ROOT":
            hiveConst = HKEY_CLASSES_ROOT;
            break;
        case "hkcu":
            hiveConst = HKEY_CURRENT_USER;
            break;
        case "hkey_current_user":
            hiveConst = HKEY_CURRENT_USER;
            break;
        case "HKCU":
            hiveConst = HKEY_CURRENT_USER;
            break;
        case "HKEY_CURRENT_USER":
            hiveConst = HKEY_CURRENT_USER;
            break;
        case "hklm":
            hiveConst = HKEY_LOCAL_MACHINE;
            break;
        case "hkey_local_machine":
            hiveConst = HKEY_LOCAL_MACHINE;
            break;
        case "HKLM":
            hiveConst = HKEY_LOCAL_MACHINE;
            break;
        case "HKEY_LOCAL_MACHINE":
            hiveConst = HKEY_LOCAL_MACHINE;
            break;
        case "hku":
            hiveConst = HKEY_USERS;
            break;
        case "hkey_users":
            hiveConst = HKEY_USERS;
            break;
        case "HKU":
            hiveConst = HKEY_USERS;
            break;
        case "HKEY_USERS":
            hiveConst = HKEY_USERS;
            break;
        case "hkcc":
            hiveConst = HKEY_CURRENT_CONFIG;
            break;
        case "hkey_current_config":
            hiveConst = HKEY_CURRENT_CONFIG;
            break;
        case "HKCC":
            hiveConst = HKEY_CURRENT_CONFIG;
            break;
        case "HKEY_CURRENT_CONFIG":
            hiveConst = HKEY_CURRENT_CONFIG;
            break;
        case "hkdd":
            hiveConst = HKEY_DYN_DATA;
            break;
        case "hkey_dyn_data":
            hiveConst = HKEY_DYN_DATA;
            break;
        case "HKDD":
            hiveConst = HKEY_DYN_DATA;
            break;
        case "HKEY_DYN_DATA":
            hiveConst = HKEY_DYN_DATA;
            break;
        case "hkpd":
            hiveConst = HKEY_PERFORMANCE_DATA;
            break;
        case "hkey_performance_data":
            hiveConst = HKEY_PERFORMANCE_DATA;
            break;
        case "HKPD":
            hiveConst = HKEY_PERFORMANCE_DATA;
            break;
        case "HKEY_PERFORMANCE_DATA":
            hiveConst = HKEY_PERFORMANCE_DATA;
            break;
        default:
            MessageBox.Show("Default");
            break;
    }
    UIntPtr key = new UIntPtr(hiveConst);
    IntPtr remKey;
    int ret = RegConnectRegistry(serverName, key, out remKey);
    UIntPtr remKeyUIntPtr = unchecked((UIntPtr)(long)(ulong)remKey);
    string result = GetRegKey64DWord(remKeyUIntPtr, keyPath, RegSAM.WOW64_64Key, stringValue);
    //MessageBox.Show(result);
    RegCloseKey(remKey);
    return (result);
}




static public string GetRegKey64DWord(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();
          byte[] byt = new byte[1024];
          RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, byt, ref lpcbData);
          Array.Reverse(byt, 0, byt.Length);
          byte[] truncated = new byte[1024];
          int i = 0;
          foreach (byte b in byt)
          {
              if (b != 0)
              {
                  truncated[i] = b;
                  i = i + 1;
              }
          }

          string hex = BitConverter.ToString(truncated);
          int index = hex.IndexOf("00");
          hex = hex.Remove(index);
          hex = hex.Replace("-", "");
          int decValue = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);
          //MessageBox.Show(hex + " " + decValue);
          return (hex + " " + decValue);
      }
      finally
      {
          if (0 != hkey) RegCloseKey(hkey);
      }
  }

QuestionChange the color of the mouse cursor (cross cursor) Pin
Wolfgang Kurz23-Mar-12 8:16
professionalWolfgang Kurz23-Mar-12 8:16 
AnswerRe: Change the color of the mouse cursor (cross cursor) Pin
OriginalGriff23-Mar-12 9:14
mveOriginalGriff23-Mar-12 9:14 
AnswerRe: Change the color of the mouse cursor (cross cursor) Pin
Philippe Mori23-Mar-12 12:35
Philippe Mori23-Mar-12 12:35 
GeneralRe: Change the color of the mouse cursor (cross cursor) Pin
Wolfgang Kurz23-Mar-12 23:08
professionalWolfgang Kurz23-Mar-12 23:08 
QuestionDirectoryInfo throwing ArgumentException Pin
MichCl23-Mar-12 4:53
MichCl23-Mar-12 4:53 
AnswerRe: DirectoryInfo throwing ArgumentException Pin
Wes Aday23-Mar-12 5:00
professionalWes Aday23-Mar-12 5:00 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
MichCl23-Mar-12 5:25
MichCl23-Mar-12 5:25 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
Wes Aday23-Mar-12 5:44
professionalWes Aday23-Mar-12 5:44 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
MichCl23-Mar-12 7:46
MichCl23-Mar-12 7:46 
AnswerRe: DirectoryInfo throwing ArgumentException Pin
fjdiewornncalwe23-Mar-12 7:09
professionalfjdiewornncalwe23-Mar-12 7:09 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
MichCl23-Mar-12 8:24
MichCl23-Mar-12 8:24 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
fjdiewornncalwe23-Mar-12 9:12
professionalfjdiewornncalwe23-Mar-12 9:12 
AnswerRe: DirectoryInfo throwing ArgumentException Pin
Alan N23-Mar-12 7:32
Alan N23-Mar-12 7:32 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
MichCl23-Mar-12 7:47
MichCl23-Mar-12 7:47 
GeneralRe: DirectoryInfo throwing ArgumentException Pin
Alan N23-Mar-12 7:55
Alan N23-Mar-12 7:55 
QuestionHow to get number of hits occurred for a particular keyword from Gnews,facebook and twitter.. Pin
ajaysinghrathore00723-Mar-12 4:03
ajaysinghrathore00723-Mar-12 4:03 
AnswerRe: How to get number of hits occurred for a particular keyword from Gnews,facebook and twitter.. Pin
Eddy Vluggen23-Mar-12 6:29
professionalEddy Vluggen23-Mar-12 6:29 

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.