本文整理汇总了C#中RegistryValueKind.GetDefault方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryValueKind.GetDefault方法的具体用法?C# RegistryValueKind.GetDefault怎么用?C# RegistryValueKind.GetDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RegistryValueKind
的用法示例。
在下文中一共展示了RegistryValueKind.GetDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRegistryValue
/// <summary>
/// Attempts to create the desired value for the specified parent.
/// </summary>
/// <param name="keyPath">The path to the key for which to create the registry value on.</param>
/// <param name="kind">The type of the registry value to create.</param>
/// <param name="name">output parameter that holds the name of the registry value that was create.</param>
/// <param name="errorMsg">output parameter that contians possible error message.</param>
/// <returns>Returns boolean value for if the operation failed or succeded.</returns>
public static bool CreateRegistryValue(string keyPath, RegistryValueKind kind, out string name, out string errorMsg)
{
name = "";
try
{
RegistryKey key = GetWritableRegistryKey(keyPath);
//Invalid can not open key
if (key == null)
{
errorMsg = "You do not have access to open registry: " + keyPath + ", try running client as administrator";
return false;
}
//Try to find available names
int i = 1;
string testName = String.Format("New Value #{0}", i);
while (key.ContainsValue(testName))
{
i++;
testName = String.Format("New Value #{0}", i);
}
name = testName;
bool success = key.SetValueSafe(name, kind.GetDefault(), kind);
//Value could not be created
if (!success)
{
errorMsg = REGISTRY_VALUE_CREATE_ERROR;
return false;
}
//Value was successfully created
errorMsg = "";
return true;
}
catch (Exception ex)
{
errorMsg = ex.Message;
return false;
}
}