本文整理汇总了C#中Microsoft.Win32.RegistryKey.DeleteSubKey方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.DeleteSubKey方法的具体用法?C# RegistryKey.DeleteSubKey怎么用?C# RegistryKey.DeleteSubKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.DeleteSubKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test01
public void Test01()
{
// [] Passing in null should throw ArgumentNullException
_rk1 = Microsoft.Win32.Registry.CurrentUser;
Action a = () => { _rk1.DeleteSubKey(null); };
Assert.Throws<ArgumentNullException>(() => { a(); });
}
示例2: DeleteKey
private void DeleteKey(RegistryKey rk, string p)
{
RegistryKey rkk =rk.OpenSubKey(p,true);
string[] names = rkk.GetSubKeyNames();
foreach (string s in names)
{
DeleteKey(rkk,s);
}
rk.DeleteSubKey(p);
}
示例3: Test03
public void Test03()
{
// [] Creating new SubKey and check that it exists
_rk1 = Microsoft.Win32.Registry.CurrentUser;
_rk1.CreateSubKey(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) == null)
{
Assert.False(true, "Error SubKey does not exist.");
}
_rk1.DeleteSubKey(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) != null)
{
Assert.False(true, "Error SubKey not removed properly");
}
}
示例4: Test02
public void Test02()
{
// [] Creating new SubKeys and get the names
_rk1 = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_testKeyName);
_rk1.CreateSubKey(_testKeyName);
if (_rk1.OpenSubKey(_testKeyName) == null)
{
Assert.False(true, "Error SubKey does not exist.");
}
_iCount = _rk1.SubKeyCount;
_rk1.DeleteSubKey(_testKeyName);
if (_rk1.SubKeyCount != _iCount - 1)
{
Assert.False(true, "Error expected==" + ((Int32)_iCount - 1).ToString() + ", got==" + _rk1.SubKeyCount);
}
if (_rk1.OpenSubKey(_testKeyName) != null)
{
Assert.False(true, "Error SubKey not removed properly");
}
}
示例5: deleteKey
//Deletes a key. Or at least tries to.
public void deleteKey(RegistryKey parentKey, string keytodelete)
{
log("Trying to delete key: " + parentKey.Name + ".");
try
{
parentKey.DeleteSubKey(keytodelete);
logsub("Success...");
}
catch (ObjectDisposedException w)
{
logsub("Key is closed so it can't be accessed.");
throw (w);
}
catch (InvalidOperationException w)
{
logsub("The key cannot be deleted because it's not empty.");
throw (w);
}
catch (ArgumentNullException w)
{
logsub("Key name is null.");
throw (w);
}
catch (ArgumentException w)
{
logsub("Key name is too long.");
throw (w);
}
catch (SecurityException w)
{
logsub("User has not enough privileges to access this key.");
throw (w);
}
}
示例6: DeleteKey
/// <summary>
/// Delete key mới trong registry
/// </summary>
/// <param name="strPath">Đường dẫn chứa key</param>
/// <param name="strKeyName">Tên key</param>
public static void DeleteKey(RegistryKey regKey, string strPath, string strKeyName)
{
regKey = regKey.CreateSubKey(strPath);
regKey.DeleteSubKey(strKeyName);
}
示例7: SaveCache
public static void SaveCache(RegistryKey rkUser) {
try {
if(fCacheDirty && (rkUser != null)) {
rkUser.DeleteSubKey("Cache", false);
using(RegistryKey key = rkUser.CreateSubKey("Cache")) {
if(key != null) {
int num = dicCacheIDLs.Count - 0x30;
List<string> list = new List<string>();
if(num > 0) {
foreach(string str in dicCacheIDLs.Keys) {
if(num <= 0) {
break;
}
byte[] buffer = dicCacheIDLs[str];
if(((buffer == null) || (buffer.Length == 0)) || (buffer[0] != 20)) {
list.Add(str);
num--;
}
}
foreach(string str2 in list) {
dicCacheIDLs.Remove(str2);
}
if(num > 0) {
list.Clear();
foreach(string str3 in dicCacheIDLs.Keys) {
if(num <= 0) {
break;
}
list.Add(str3);
num--;
}
foreach(string str4 in list) {
dicCacheIDLs.Remove(str4);
}
}
}
foreach(string str5 in dicCacheIDLs.Keys) {
key.SetValue(str5, dicCacheIDLs[str5]);
}
}
}
}
fCacheDirty = false;
}
catch(Exception exception) {
QTUtility2.MakeErrorLog(exception, null, false);
}
}
示例8: Win32DeleteSubKey
public static int Win32DeleteSubKey(RegistryKey parentKey, string key)
{
int iRet = 0;
try
{
parentKey.DeleteSubKey(key, true);
}
catch (Exception ex)
{
iRet = -1;
Logger.LogException("Win32DeleteSubKeyValue : ", ex);
}
return iRet;
}
示例9: DeleteSubkeysRecursively
private void DeleteSubkeysRecursively(RegistryKey regKey)
{
try
{
foreach (string subKeyName in regKey.GetSubKeyNames())
{
RegistryKey tmpKey = regKey.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree);
if (regKey.OpenSubKey(subKeyName).SubKeyCount == 0)
{
foreach (string regValue in tmpKey.GetValueNames())
{
tmpKey.DeleteValue(regValue);
}
regKey.DeleteSubKey(subKeyName);
tmpKey.Close();
}
else
DeleteSubkeysRecursively(tmpKey);
}
}
catch
{
}
}
示例10: DeleteKey
public static bool DeleteKey (RegistryKey registryKey, string key)
{
if (registryKey == null) throw new NolmeArgumentNullException ();
bool bResult = false;
if (registryKey != null)
{
registryKey.DeleteSubKey (key);
bResult = !Win32RegistryUtility.IsExists (registryKey, key);
}
return bResult;
}
示例11: Save
/// <summary>
/// Save all the information in a class to the registry. This method iterates through
/// all members of the specified class and saves them to the registry.
/// </summary>
/// <param name="settings">An object that holds all the desired settings</param>
/// <param name="Key">The registry key in which to save data</param>
public static void Save(object settings, RegistryKey Key)
{
RegistryKey subkey;
// Iterate through each Field of the specified class using "Reflection".
// The name of each Field is used to generate the name of the registry
// value, sometimes with appended characters to specify elements of more
// complex Field types such as a Font or a Point. Arrays are stored by
// creating a new subkey with the same name as the Field. The subkey holds
// values with names that are just the integers 0,1,2,... giving the index
// of each value.
//
foreach(FieldInfo fi in settings.GetType().GetFields(
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
// If this field is an Enum it needs to be handled separately. The text
// name for the enum is written to the registry.
if(fi.FieldType.IsEnum)
{
Key.SetValue(fi.Name,Enum.GetName(fi.FieldType,fi.GetValue(settings)));
}
// Otherwise each different field type is handled case by case using
// a large switch statement
else
{
// Test the name of the Field type, converted to lower case
switch (fi.FieldType.Name.ToLower())
{
case "string":
Key.SetValue(fi.Name,(string)fi.GetValue(settings));
break;
case "boolean":
Key.SetValue(fi.Name,(bool)fi.GetValue(settings));
break;
case "int32":
Key.SetValue(fi.Name,(int)fi.GetValue(settings));
break;
case "decimal":
decimal TheDecimal=(decimal)fi.GetValue(settings);
Key.SetValue(fi.Name,(int)TheDecimal);
break;
case "single":
Key.SetValue(fi.Name,(float)fi.GetValue(settings));
break;
case "double":
Key.SetValue(fi.Name,(double)fi.GetValue(settings));
break;
// Store a Point as two separate integers
case "point":
Point point=(Point)fi.GetValue(settings);
Key.SetValue(fi.Name+".X",point.X);
Key.SetValue(fi.Name+".Y",point.Y);
break;
// Store a Size as two separate integers
case "size":
Size size=(Size)fi.GetValue(settings);
Key.SetValue(fi.Name+".Height",size.Height);
Key.SetValue(fi.Name+".Width",size.Width);
break;
// byte arrays are a native registry type and thus easy to handle
case "byte[]":
byte[] bytes = (byte[])fi.GetValue(settings);
if(bytes==null)break;
Key.SetValue(fi.Name,bytes);
break;
// string arrays are a native registry type and thus easy to handle
case "string[]":
string[] strings = (string[])fi.GetValue(settings);
if(strings==null)break;
Key.SetValue(fi.Name,strings);
break;
// For arrays that aren't native registry types, create a subkey and then
// create values that are numbered sequentially. First delete the subkey
// if it already exists then refill it with all the values of the array.
case "int32[]":
int[] numbers = (int[])fi.GetValue(settings);
if(numbers==null)break;
Key.DeleteSubKey(fi.Name,false); // first delete all the old values
subkey=Key.CreateSubKey(fi.Name);
for(int i=0;i<numbers.Length;i++)
{
subkey.SetValue(i.ToString(),numbers[i]);
//.........这里部分代码省略.........
示例12: DelRegSubKey
/// 删除路径为keypath的子项
private bool DelRegSubKey(RegistryKey rootkey, string keypath)
{
try
{
rootkey.DeleteSubKey(keypath);
return true;
}
catch
{
return false;
}
}
示例13: DeleteConfigKey
private void DeleteConfigKey(RegistryKey parentKey, string subkeyname)
{
parentKey.DeleteSubKey(subkeyname, false);
}
示例14: ClearKey
/// <summary>
/// Static function that clears out the contents of a key
/// </summary>
/// <param name="key">Key to be cleared</param>
public static void ClearKey( RegistryKey key )
{
foreach( string name in key.GetValueNames() )
key.DeleteValue( name );
// TODO: This throws under Mono - Restore when bug is fixed
//foreach( string name in key.GetSubKeyNames() )
// key.DeleteSubKeyTree( name );
foreach (string name in key.GetSubKeyNames())
{
ClearSubKey(key, name);
// TODO: Remove this test when Mono bug is fixed
if ( NUnit.Core.RuntimeFramework.CurrentFramework.Runtime == NUnit.Core.RuntimeType.Net )
key.DeleteSubKey( name );
}
}
示例15: SaveGroupTreeView
private void SaveGroupTreeView(RegistryKey rkUser) {
QTUtility.GroupPathsDic.Clear();
QTUtility.StartUpGroupList.Clear();
QTUtility.dicGroupShortcutKeys.Clear();
QTUtility.dicGroupNamesAndKeys.Clear();
List<PluginKey> list = new List<PluginKey>();
int num = 1;
foreach(TreeNode node in tnGroupsRoot.Nodes) {
MenuItemArguments tag = (MenuItemArguments)node.Tag;
if(tag == MIA_GROUPSEP) {
QTUtility.GroupPathsDic["Separator" + num++] = string.Empty;
}
else if(node.Nodes.Count > 0) {
string text = node.Text;
if(text.Length > 0) {
string str2 = node.Nodes.Cast<TreeNode>()
.Select(node2 => node2.Name)
.Where(name => name.Length > 0)
.StringJoin(";");
if(str2.Length > 0) {
string item = text.Replace(";", "_");
QTUtility.GroupPathsDic[item] = str2;
if(node.NodeFont == fntStartUpGroup) {
QTUtility.StartUpGroupList.Add(item);
}
if(tag.KeyShortcut != 0) {
if(tag.KeyShortcut > 0x100000) {
QTUtility.dicGroupShortcutKeys[tag.KeyShortcut] = item;
}
QTUtility.dicGroupNamesAndKeys[item] = tag.KeyShortcut;
list.Add(new PluginKey(item, new int[] { tag.KeyShortcut }));
}
}
}
}
}
rkUser.DeleteSubKey("Groups", false);
using(RegistryKey key = rkUser.CreateSubKey("Groups")) {
if(key != null) {
foreach(string str4 in QTUtility.GroupPathsDic.Keys) {
key.SetValue(str4, QTUtility.GroupPathsDic[str4]);
}
}
}
rkUser.DeleteValue("ShortcutKeys_Group", false);
if(list.Count > 0) {
QTUtility2.WriteRegBinary(list.ToArray(), "ShortcutKeys_Group", rkUser);
}
}