本文整理汇总了C#中Microsoft.Win32.RegistryKey.DeleteValue方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.DeleteValue方法的具体用法?C# RegistryKey.DeleteValue怎么用?C# RegistryKey.DeleteValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.DeleteValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: SystemInformation
internal SystemInformation(RegistryKey key)
{
bool loaded = false;
LastStartupDateTime = DateTime.Now;
try
{
if (key.GetValue(KeyInstallation) != null)
{
InstallationDateTime = DateTime.ParseExact(
(string)key.GetValue(KeyInstallation), "O",
CultureInfo.InvariantCulture
);
string lastReportDate = (string)key.GetValue(KeyLastReport);
if (lastReportDate != null)
{
LastReportDateTime = DateTime.ParseExact(
lastReportDate, "O", CultureInfo.InvariantCulture
);
}
#if CACHE_SYSTEM_INFORMATION
OperatingSystem = (string)key.GetValue(KeyOperatingSystem);
OperationSystemVersion = (string)key.GetValue(KeyOperationSystemVersion);
Cpu = (string)key.GetValue(KeyCpu);
CpuInformation = (string)key.GetValue(KeyCpuInformation);
#endif
loaded = true;
}
}
catch
{
// If we were unable to load the settings, initialize new settings.
}
if (!loaded)
{
Detect();
key.SetValue(KeyInstallation, InstallationDateTime.ToString("O"));
if (key.GetValue(KeyLastReport) != null)
key.DeleteValue(KeyLastReport);
#if CACHE_SYSTEM_INFORMATION
key.SetValue(KeyOperatingSystem, OperatingSystem);
key.SetValue(KeyOperationSystemVersion, OperationSystemVersion);
key.SetValue(KeyCpu, Cpu);
key.SetValue(KeyCpuInformation, CpuInformation);
#endif
}
#if !CACHE_SYSTEM_INFORMATION
DetectSystemInformation();
#endif
}
示例3: RenameFontName
public static void RenameFontName(RegistryKey key, string original, string target, string value)
{
// TODO: Use transection.
key.SetValue(target, value);
key.DeleteValue(original);
}
示例4: 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);
}
示例5: SafeDeleteRegistryValue
public static void SafeDeleteRegistryValue(RegistryKey regKey, String keyName)
{
// Can't extend Microsoft.Win32.RegistryKey since its sealed, hence has to put this in Utils.cs
try {
regKey.DeleteValue(keyName);
} catch (ArgumentException) {
}
}
示例6: CreateComponentValue
internal void CreateComponentValue(RegistryKey componentKey, string name, object value, RegistryValueKind kind)
{
if (null == componentKey)
throw new ArgumentNullException("Unable to find specified registry key.");
if (componentKey.GetValue(name, null) != null && componentKey.GetValueKind(name) != kind)
componentKey.DeleteValue(name, false);
componentKey.SetValue(name, value, kind);
}
示例7: SetCheckedStateFromString
/// <summary>
/// Updates the checked state of the <paramref name="chk"/> if the <paramref name="valueName"/>
/// evaluates to true (i.e., '1' (REG_SZ)) for the passed in <paramref name="registryKey"/>.
/// However, if <paramref name="inverse"/> is to true, it updates the checkbox state in reverse manner, i.e.,
/// if the <paramref name="valueName"/> evaluates to true (i.e., 1), checkbox is set to unchecked.
/// </summary>
/// <param name="chk"></param>
/// <param name="registryKey"></param>
/// <param name="valueName"></param>
/// <param name="inverse"></param>
internal static void SetCheckedStateFromString(this CheckBox chk, RegistryKey registryKey,
string valueName, bool inverse = false)
{
try {
string val = (string) registryKey.GetValue(valueName);
chk.IsChecked = inverse ? Utils.ReversedStringToBool(val) : Utils.StringToBool(val);
} catch (InvalidCastException) {
registryKey.DeleteValue(valueName, false);
chk.IsChecked = false;
}
}
示例8: ConditionalSetValue
private void ConditionalSetValue( RegistryKey key, String valueName, String value )
{
if (String.IsNullOrEmpty( value ))
{
key.DeleteValue( valueName, false );
}
else
{
key.SetValue( valueName, value );
}
}
示例9: 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();
}
示例10: SetCheckedState
/// <summary>
/// Updates the checked state of the <paramref name="chk"/> if the <paramref name="valueName"/>
/// evaluates to true (i.e., 1 (REG_DWORD or REG_QWORD)) for the passed in <paramref name="registryKey"/>.
/// However, if <paramref name="inverse"/> is to true, it updates the checkbox state in reverse manner, i.e.,
/// if the <paramref name="valueName"/> evaluates to true (i.e., 1), checkbox is set to unchecked.
/// </summary>
/// <param name="chk"></param>
/// <param name="registryKey"></param>
/// <param name="valueName"></param>
/// <param name="inverse"></param>
/// <param name="nullAsTrue"></param>
internal static void SetCheckedState(this CheckBox chk, RegistryKey registryKey,
string valueName, bool inverse=false, bool nullAsTrue=false)
{
try {
int? val = (int?) registryKey.GetValue(valueName);
if (inverse && !val.HasValue && nullAsTrue) {
chk.IsChecked = true;
return;
}
chk.IsChecked = inverse ? Utils.ReversedIntToBool(val) : Utils.IntToBool(val);
} catch (InvalidCastException) {
registryKey.DeleteValue(valueName, false);
chk.IsChecked = false;
}
}
示例11: unregisterProgram
public bool unregisterProgram(string appName)
{
try
{
startupKey = Registry.CurrentUser.OpenSubKey(runKey, true);
startupKey.DeleteValue(appName, true);
}
catch (Exception)
{
return false;
}
finally
{
startupKey.Close();
}
return true;
}
示例12: deleteValue
private static bool deleteValue(int Section, string Location, string Value)
{
key = getKeySection(Section);
try
{
key = key.OpenSubKey(Location,true);
key.DeleteValue(Value, false);
}
catch
{
return false;
}
finally
{
key.Close();
}
return true;
}
示例13: Delete
public static RegistryError Delete(RegistryKey regKey, string location, string value)
{
RegistryError rerr = RegistryError.None;
try
{
regKey = regKey.OpenSubKey(location, true);
regKey.DeleteValue(value, false);
}
catch (Exception e)
{
rerr = RegistryError.Error;
Tracer.Error(e);
}
finally
{
regKey.Close();
}
return rerr;
}
示例14: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKeyName2 += counter.ToString();
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKeyName2) != null)
_rk1.DeleteSubKeyTree(_testKeyName2);
if (_rk1.GetValue(_testKeyName2) != null)
_rk1.DeleteValue(_testKeyName2);
_rk2 = _rk1.CreateSubKey(_testKeyName2);
Random rand = new Random(10);
Byte[] byteArr = new Byte[rand.Next(0, 100)];
rand.NextBytes(byteArr);
_objArr = new Object[6];
_objArr[0] = (Int32)(rand.Next(Int32.MinValue, Int32.MaxValue));
_objArr[1] = (Int64)(rand.NextDouble() * Int64.MaxValue);
_objArr[2] = (String)"Hello World";
_objArr[3] = (String)"Hello %path5% World";
_objArr[4] = new String[] { "Hello World", "Hello %path% World" };
_objArr[5] = (Byte[])(byteArr);
}
示例15: AutoStartUpC
private void AutoStartUpC(object sender, EventArgs e)
{
rsg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\");
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", true);
rsg.DeleteValue(mainwindow.programname);
mainwindow.displaytips("已经取消了哦", 2000);
startup.Checked = false;
startupc.Checked = true;
}