本文整理汇总了C#中RegistryValueKind类的典型用法代码示例。如果您正苦于以下问题:C# RegistryValueKind类的具体用法?C# RegistryValueKind怎么用?C# RegistryValueKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegistryValueKind类属于命名空间,在下文中一共展示了RegistryValueKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegEnumValue
private static int RegEnumValue (IntPtr keyBase,
int index, StringBuilder nameBuffer,
ref int nameLength, IntPtr reserved,
ref RegistryValueKind type, IntPtr data, IntPtr dataLength)
{
throw new System.NotImplementedException();
}
示例2: set
public bool set(String key, String val, RegistryValueKind type)
{
RegistryKey reg;
int result = 1;
string[] keysplit = (key).Split(System.IO.Path.DirectorySeparatorChar);
string root = keysplit[0];
string name = keysplit[keysplit.Length - 1];
string path = key.Replace(root + @"\", "").Replace(@"\" + name, "");
switch (root)
{
case "HKCU":
reg = Registry.CurrentUser;
break;
case "HKLM":
reg = Registry.LocalMachine;
break;
default:
return false;
}
reg = reg.CreateSubKey(path);
if (reg == null) result = 0;
reg.SetValue(name, val, type);
object regObj = reg.GetValue(name);
if (regObj == null) result = 0;
reg.Close();
reg = null;
if (result == 0) return false; else return true;
}
示例3: ConvertValueToUIntFromRegistryIfNeeded
public static object ConvertValueToUIntFromRegistryIfNeeded(string name, object value, RegistryValueKind kind)
{
try
{
if (kind == RegistryValueKind.DWord)
{
value = (int) value;
if (((int) value) < 0)
{
value = BitConverter.ToUInt32(BitConverter.GetBytes((int) value), 0);
}
return value;
}
if (kind == RegistryValueKind.QWord)
{
value = (long) value;
if (((long) value) < 0L)
{
value = BitConverter.ToUInt64(BitConverter.GetBytes((long) value), 0);
}
}
}
catch (IOException)
{
}
return value;
}
示例4: RegSetValueEx
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
String lpData,
int cbData);
示例5: ConvertValueToUIntFromRegistryIfNeeded
public static object ConvertValueToUIntFromRegistryIfNeeded(string name, object value, RegistryValueKind kind)
{
try
{
// Workaround for CLR bug that doesn't support full range of DWORD or QWORD
if (kind == RegistryValueKind.DWord)
{
value = (int)value;
if ((int)value < 0)
{
value = BitConverter.ToUInt32(BitConverter.GetBytes((int)value), 0);
}
}
else if (kind == RegistryValueKind.QWord)
{
value = (long)value;
if ((long)value < 0)
{
value = BitConverter.ToUInt64(BitConverter.GetBytes((long)value), 0);
}
}
}
catch (System.IO.IOException)
{
// This is expected if the value does not exist.
}
return value;
}
示例6: RegSzOddByteLength
public void RegSzOddByteLength(RegistryValueKind kind, byte[] contents)
{
const string TestValueName = "CorruptData2";
SafeRegistryHandle handle = TestRegistryKey.Handle;
int ret = Interop.mincore.RegSetValueEx(handle, TestValueName, 0,
kind, contents, contents.Length);
Assert.Equal(0, ret);
try
{
object o = TestRegistryKey.GetValue(TestValueName);
string s;
if (kind == RegistryValueKind.MultiString)
{
Assert.IsType<string[]>(o);
var strings = (string[])o;
Assert.Equal(1, strings.Length);
s = strings[0];
}
else
{
Assert.IsType<string>(o);
s = (string)o;
}
Assert.Equal(2, s.Length);
Assert.Equal(0x506, s[0]);
Assert.Equal(0x6, s[1]);
}
finally
{
TestRegistryKey.DeleteValue(TestValueName);
}
}
示例7: PutObjectValue
public static void PutObjectValue(string key, string valuename, string value, bool bHKLM, RegistryValueKind kind = RegistryValueKind.Unknown)
{
using (RegistryKey regkey = bHKLM ? Registry.LocalMachine.CreateSubKey(key) : Registry.CurrentUser.CreateSubKey(key))
{
regkey.SetValue(valuename, value, kind);
}
}
示例8: SetPolicyRegistryKey
private static void SetPolicyRegistryKey(string path, string name, object value, RegistryValueKind kind)
{
const string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Group Policy Objects";
using (var rk = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default))
{
List<string> certKeys;
using (var srk = rk.OpenSubKey(keyPath))
{
if (srk == null)
{
throw new ApplicationException("无法打开注册表项:" + keyPath);
}
certKeys = srk.GetSubKeyNames().Where(x => x.EndsWith("Machine")).Select(x => string.Format("{0}\\{1}\\{2}", keyPath, x, path))
//.Where(x => rk.OpenSubKey(x) == null)
.ToList();
}
foreach (var key in certKeys)
{
using (var skey = rk.CreateSubKey(key))
{
if (skey != null) skey.SetValue(name, value, kind);
}
}
}
}
示例9: RegQueryValueEx
static extern uint RegQueryValueEx(
UIntPtr hKey,
string lpValueName,
IntPtr lpReserved,
out RegistryValueKind lpType,
StringBuilder lpData,
ref int lpcbData);
示例10: RegistryValueSnapshot
public RegistryValueSnapshot(string name, string value, RegistryValueKind type)
: this()
{
this.Name = name;
this.Value = value;
this.Type = type;
}
示例11: RegValueSpec
/// <summary>
/// Constructs a key value pair with the given valueName, valueObject, and valueKind.
/// Sets valueKind to RegistryValueKind.Unknown which will cause any call to RegistryKey.SetValue to attempt to dynamically derive the type from the actual type of the ValueObject.
/// </summary>
public RegValueSpec(string valueName, object valueObject, RegistryValueKind valueKind)
: this()
{
ValueName = valueName;
ValueObject = valueObject;
ValueKind = valueKind;
}
示例12: ConvertUIntToValueForRegistryIfNeeded
public static object ConvertUIntToValueForRegistryIfNeeded(object value, RegistryValueKind kind)
{
if (kind == RegistryValueKind.DWord)
{
try
{
value = BitConverter.ToInt32(BitConverter.GetBytes(Convert.ToUInt32(value, CultureInfo.InvariantCulture)), 0);
}
catch (OverflowException)
{
}
return value;
}
if (kind == RegistryValueKind.QWord)
{
try
{
value = BitConverter.ToInt64(BitConverter.GetBytes(Convert.ToUInt64(value, CultureInfo.InvariantCulture)), 0);
}
catch (OverflowException)
{
}
}
return value;
}
示例13: AddinKeyValue
internal AddinKeyValue(WatchController root, AddinKey parent, string valueName, RegistryValueKind valueKind, object value)
{
_root = root;
_parent = parent;
_valueName = valueName;
_valueKind = valueKind;
_value = value;
}
示例14: ConfigRegistryItem
public ConfigRegistryItem(ConfigEngine engine, string itemName, string path, string name, object value, RegistryValueKind kind)
: base(engine, itemName)
{
_path = path;
_name = name;
_value = value;
_kind = kind;
}
示例15: RegChange
public RegChange(RegOperations regOp, RegBasekeys regBase, string subKey, bool is32BitKey)
{
RegOperation = regOp;
RegBasekey = regBase;
SubKey = subKey;
RegValueKind = RegistryValueKind.String;
Is32BitKey = is32BitKey;
}