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;
}
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
Post a Comment