How to Get Registry

---------------Set Registry Key--------------------------------
 public static bool GenRegKey(string strKeyValue)
        {
            string strKeyName = "AK_ECDRKEY";
            Microsoft.Win32.RegistryKey key;
            if (!CheckRegKeyExistsOrNot(strKeyName))
            {
                try
                {
                    key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(strKeyName);
                    key.SetValue(strKeyName, strKeyValue);
                    key.Close();
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }



-------------------Check Registry Key-----------------------------
public static bool CheckRegKeyExistsOrNot(string strKeyName)
        {
            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strKeyName);
            if (key == null)
            {
                return false;
            }
            else
            {
                key.Close();
                return true;
            }
        }
-----------------Get Registry Key from system----------------
 #region GetKey
        private string GetKey()
        {
            string strKeyName = "AK_ECDRKEY";
            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strKeyName);
            if (key == null)
            {
                return "";
            }
            else
            {
                string keyVal = key.GetValue("AK_ECDRKEY").ToString();
                key.Close();
                return keyVal;
            }
        }
        #endregion



--------------------GEt MAC Address----------------------
 public string GetMACAddress()
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            String sMacAddress = string.Empty;
            foreach (NetworkInterface adapter in nics)
            {
                if (sMacAddress == String.Empty)
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    sMacAddress = adapter.GetPhysicalAddress().ToString();
                }
            } return sMacAddress;
        }

Comments

Popular posts from this blog

ASP.NET Session States in SQL Server Mode

How to find client's MAC Address in Asp.Net and C#.net

Use XML Data For Save in Database