本文整理汇总了C#中Microsoft.Win32.RegistryKey.DeleteSubKeyTree方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.DeleteSubKeyTree方法的具体用法?C# RegistryKey.DeleteSubKeyTree怎么用?C# RegistryKey.DeleteSubKeyTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.DeleteSubKeyTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteSubKeyTree
/// <summary>
/// Helper function to recursively delete a sub-key (swallows errors in the
/// case of the sub-key not existing
/// </summary>
/// <param name="root">Root to delete key from</param>
/// <param name="subKey">Name of key to delete</param>
public static void DeleteSubKeyTree(RegistryKey root, string subKey)
{
// delete the specified sub-key if if exists (swallow the error if the
// sub-key does not exist)
try { root.DeleteSubKeyTree(subKey); }
catch (ArgumentException) { }
}
示例2: TestInitialize
public void TestInitialize()
{
_rk = Registry.CurrentUser.OpenSubKey("Software", true);
if (_rk.OpenSubKey(_testKeyName) != null)
_rk.DeleteSubKeyTree(_testKeyName);
if (_rk.OpenSubKey(_testVolatileKeyName) != null)
_rk.DeleteSubKeyTree(_testVolatileKeyName);
if (_rk.OpenSubKey(_testNonVolatileKeyName) != null)
_rk.DeleteSubKeyTree(_testNonVolatileKeyName);
if (_rk.OpenSubKey(_testRegularKey) != null)
_rk.DeleteSubKeyTree(_testRegularKey);
}
示例3: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_madeUpKey = _madeUpKey + counter.ToString();
_rk = Registry.CurrentUser.OpenSubKey("Software", true);
if (_rk.OpenSubKey(_madeUpKey) != null)
_rk.DeleteSubKeyTree(_madeUpKey);
if (_rk.OpenSubKey(_subKeyExists) != null)
_rk.DeleteSubKeyTree(_subKeyExists);
if (_rk.OpenSubKey(_subKeyExists2) != null)
_rk.DeleteSubKeyTree(_subKeyExists2);
}
示例4: RenameSubKey
/// <summary>
/// Renames a subkey of the passed in registry key since
/// the Framework totally forgot to include such a handy feature.
/// </summary>
/// <param name="regKey">The RegistryKey that contains the subkey
/// you want to rename (must be writeable)</param>
/// <param name="subKeyName">The name of the subkey that you want to rename
/// </param>
/// <param name="newSubKeyName">The new name of the RegistryKey</param>
/// <returns>True if succeeds</returns>
public static bool RenameSubKey(RegistryKey parentKey,
string subKeyName, string newSubKeyName)
{
CopyKey(parentKey, subKeyName, newSubKeyName);
parentKey.DeleteSubKeyTree(subKeyName);
return true;
}
示例5: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKeyName += counter.ToString();
_testKeyName2 += counter.ToString();
rk1 = Microsoft.Win32.Registry.CurrentUser;
if (rk1.OpenSubKey(_testKeyName2) != null)
rk1.DeleteSubKeyTree(_testKeyName2);
if (rk1.GetValue(_testKeyName2) != null)
rk1.DeleteValue(_testKeyName2, false);
if (rk1.GetValue(_testKeyName) != null)
rk1.DeleteValue(_testKeyName);
if (rk1.OpenSubKey(_testKeyName) != null)
rk1.DeleteSubKeyTree(_testKeyName);
}
示例6: Test04
public void Test04()
{
// [] Give subkey a value and then delete tree
_rk1 = Microsoft.Win32.Registry.CurrentUser;
_rk1.CreateSubKey(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) == null)
{
Assert.False(true, "Error Could not get subkey");
}
_rk1.DeleteSubKeyTree(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) != null)
{
Assert.False(true, "Error SubKey still there");
}
// CreateSubKey should just open a SubKeyIfIt already exists
_rk2 = _rk1.CreateSubKey(_testKeyName);
_rk2.CreateSubKey("BLAH");
if (_rk1.OpenSubKey(_testKeyName).OpenSubKey("BLAH") == null)
{
Assert.False(true, "Error Expected get not returned");
}
_rk2.DeleteSubKey("BLAH");
if (_rk2.OpenSubKey("BLAH") != null)
{
Assert.False(true, "Error SubKey was not deleted");
}
}
示例7: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKey += counter.ToString();
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKey) != null)
_rk1.DeleteSubKeyTree(_testKey);
if (_rk1.GetValue(_testKey) != null)
_rk1.DeleteValue(_testKey);
//created the test key. if that failed it will cause many of the test scenarios below fail.
try
{
_rk1 = Microsoft.Win32.Registry.CurrentUser;
_rk2 = _rk1.CreateSubKey(_testKey);
if (_rk2 == null)
{
Assert.False(true, "ERROR: Could not create test subkey, this will fail a couple of scenarios below.");
}
else
_keyString = _rk2.ToString();
}
catch (Exception e)
{
Assert.False(true, "ERROR: unexpected exception, " + e.ToString());
}
}
示例8: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKeyName = _testKeyName + counter.ToString();
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKeyName) != null)
_rk1.DeleteSubKeyTree(_testKeyName);
}
示例9: Test01
public void Test01()
{
// [] Passing in null should throw ArgumentNullException
_rk1 = Microsoft.Win32.Registry.CurrentUser;
Action a = () => { _rk1.DeleteSubKeyTree(null); };
Assert.Throws<ArgumentNullException>(() => { a(); });
}
示例10: DeleteKey
private static bool DeleteKey(RegistryKey parent, string path)
{
if (KeyExists(parent, path))
{
parent.DeleteSubKeyTree(path);
return true;
}
return false;
}
示例11: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKey += counter.ToString();
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKey) != null)
_rk1.DeleteSubKeyTree(_testKey);
if (_rk1.GetValue(_testKey) != null)
_rk1.DeleteValue(_testKey);
_rk2 = _rk1.CreateSubKey(_testKey);
_keyString = _rk2.ToString();
}
示例12: RenameSubKey
/// <summary>
/// Renames a subkey of the passed in registry key since
/// the Framework totally forgot to include such a handy feature.
/// </summary>
/// <param name="regKey">The RegistryKey that contains the subkey
/// you want to rename (must be writeable)</param>
/// <param name="subKeyName">The name of the subkey that you want to rename
/// </param>
/// <param name="newSubKeyName">The new name of the RegistryKey</param>
/// <returns>True if succeeds</returns>
public static bool RenameSubKey(RegistryKey parentKey,
string subKeyName, string newSubKeyName)
{
try
{
CopyKey(parentKey, subKeyName, newSubKeyName);
parentKey.DeleteSubKeyTree(subKeyName);
return true;
}
catch (Exception)
{
return false;
}
}
示例13: SetRegistryKeyFromBool
/// <summary>
/// Sets the value of <paramref name="keyName"/> in <paramref name="registryKey"/> to 1 if
/// <paramref name="val"/> is equal to true, otherwise sets it to 0.
/// </summary>
/// <param name="val"></param>
/// <param name="registryKey"></param>
/// <param name="keyName"></param>
public static void SetRegistryKeyFromBool(bool? val, RegistryKey registryKey, String keyName)
{
RegistryKey newKey = registryKey.OpenSubKey(keyName, true);
if (val == true && newKey == null) {
registryKey.CreateSubKey(keyName);
} else {
if (newKey != null) {
registryKey.DeleteSubKeyTree(keyName);
}
}
if (newKey != null) {
newKey.Close();
}
}
示例14: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKeyName = "REG_TEST_12" + counter.ToString();
_testValueName = "TestValue";
_testStringName = "TestString" + counter.ToString();
_testString = "Hello World!†þ";
_testValue = 11;
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKeyName) != null)
_rk1.DeleteSubKeyTree(_testKeyName);
_rk2 = _rk1.CreateSubKey(_testKeyName);
_rk2.Dispose();
}
示例15: Test03
public void Test03()
{
// [] Creating new SubKey and deleting it
_rk1 = Microsoft.Win32.Registry.CurrentUser;
_rk1.CreateSubKey(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) == null)
{
Assert.False(true, "Error SubKey does not exist.");
}
_rk1.DeleteSubKeyTree(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) != null)
{
Assert.False(true, "Error SubKey not removed properly");
}
}