Exemplo n.º 1
0
        /// <summary>
        /// Get registry key call to imports
        /// </summary>
        /// <param name="inHive"></param>
        /// <param name="inKeyName"></param>
        /// <param name="in32or64key"></param>
        /// <param name="inPropertyName"></param>
        /// <returns></returns>
        static public string GetRegKey64(UIntPtr inHive, String inKeyName, RegistrySAM in32or64key, String inPropertyName)
        {
            var    hkey = 0;
            string Age;

            try
            {
                Logger.Log("Open registry handle", Logger.MessageLevel.Verbose, AppName);
                var lResult = NativeMethods.RegOpenKeyEx(inHive, inKeyName, 0, (int)RegistrySAM.QueryValue | (int)in32or64key, out hkey);
                if (0 != lResult)
                {
                    return(null);
                }
                uint lpType    = 0;
                uint lpcbData  = 1024;
                var  AgeBuffer = new StringBuilder(1024);
                Logger.Log("Get value from registry", Logger.MessageLevel.Verbose, AppName);
                NativeMethods.RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, AgeBuffer, ref lpcbData);
                Age = AgeBuffer.ToString();
            }
            finally
            {
                Logger.Log("Close registry handle", Logger.MessageLevel.Verbose, AppName);
                if (0 != hkey)
                {
                    NativeMethods.RegCloseKey(hkey);
                }
            }
            return(Age);
        }
 /// <summary>
 /// Get registry key call to imports
 /// </summary>
 /// <param name="inHive"></param>
 /// <param name="inKeyName"></param>
 /// <param name="in32or64key"></param>
 /// <param name="inPropertyName"></param>
 /// <returns></returns>
 static public string GetRegKey64(UIntPtr inHive, String inKeyName, RegistrySAM in32or64key, String inPropertyName)
 {
     var hkey = 0;
     string Age;
     try
     {
         Logger.Log("Open registry handle", Logger.MessageLevel.Verbose, AppName);
         var lResult = NativeMethods.RegOpenKeyEx(inHive, inKeyName, 0, (int)RegistrySAM.QueryValue | (int)in32or64key, out hkey);
         if (0 != lResult) return null;
         uint lpType = 0;
         uint lpcbData = 1024;
         var AgeBuffer = new StringBuilder(1024);
         Logger.Log("Get value from registry", Logger.MessageLevel.Verbose, AppName);
         NativeMethods.RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, AgeBuffer, ref lpcbData);
         Age = AgeBuffer.ToString();
     }
     finally
     {
         Logger.Log("Close registry handle", Logger.MessageLevel.Verbose, AppName);
         if (0 != hkey) NativeMethods.RegCloseKey(hkey);
     }
     return Age;
 }