本文整理汇总了C#中RegistryView类的典型用法代码示例。如果您正苦于以下问题:C# RegistryView类的具体用法?C# RegistryView怎么用?C# RegistryView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegistryView类属于命名空间,在下文中一共展示了RegistryView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadLicenseFromRegistry
string ReadLicenseFromRegistry(RegistryView view)
{
try
{
using (var rootKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, view))
using (var registryKey = rootKey.OpenSubKey(keyPath))
{
if (registryKey == null)
{
return null;
}
var licenseValue = registryKey.GetValue("License", null);
if (licenseValue is string[])
{
return string.Join(" ", (string[])licenseValue);
}
return (string)licenseValue;
}
}
catch
{
return null;
}
}
示例2: RegistryKeyExists
static bool RegistryKeyExists(string keyName, RegistryView registryView)
{
var localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView);
localKey = localKey.OpenSubKey(keyName);
return localKey != null;
}
示例3: ReadKey
public static object ReadKey(RegistryHive hive, RegistryView view, string subkey, string name)
{
// open root
RegistryKey rootKey = Microsoft.Win32.RegistryKey.OpenBaseKey(hive, view);
if (rootKey == null)
{
return null;
}
// look for key
RegistryKey key = rootKey.OpenSubKey(subkey);
if (key == null)
{
return null;
}
// look for value
object value = key.GetValue(name);
if (value == null)
{
return null;
}
return value;
}
示例4: FromHandle
public IRegistryKey FromHandle(
SafeRegistryHandle handle,
RegistryView view
)
{
return new RegistryKeyWrap(RegistryKey.FromHandle(handle, view));
}
示例5: OpenBaseKey
public IRegistryKey OpenBaseKey(
RegistryHive hKey,
RegistryView view
)
{
return new RegistryKeyWrap(RegistryKey.OpenBaseKey(hKey, view));
}
示例6: add_key
private void add_key(IList<RegistryKey> keys, RegistryHive hive, RegistryView view)
{
FaultTolerance.try_catch_with_logging_exception(
() => keys.Add(RegistryKey.OpenBaseKey(hive, view)),
"Could not open registry hive '{0}' for view '{1}'".format_with(hive.to_string(), view.to_string()),
logWarningInsteadOfError: true);
}
示例7: Init
public static void Init(RegistryView settingsRoot, IDictionary<string, IEnumerable<string>> options)
{
if (BitlySettings == null) {
BitlySettings = settingsRoot["bitly"];
bitlyUsername = BitlySettings["#username"].StringValue;
bitlySecret = BitlySettings["#password"].EncryptedStringValue;
foreach (var arg in options.Keys) {
var argumentParameters = options[arg];
var last = argumentParameters.LastOrDefault();
switch (arg) {
case "bitly-username":
bitlyUsername = last;
BitlySettings["#username"].StringValue = bitlyUsername;
break;
case "bitly-secret":
bitlySecret = last;
BitlySettings["#password"].EncryptedStringValue = bitlySecret;
break;
}
}
}
}
示例8:
public RegistrySettingsProvider
(RegistryHive hKey, RegistryView view = RegistryView.Default, string baseKey = null)
{
this.hKey = hKey;
this.view = view;
this.baseKey = baseKey ?? ProductInfo.Company + "\\" + ProductInfo.Product;
}
示例9: OpenRegistryHive
/// <summary>
/// Given a registry path, locate the correct root key and return the relative path. For example, when the user gives the absolute registry path
///
/// HKEY_LOCAL_MACHINE\Software\Microsoft
///
/// you really have two parts: HKEY_LOCAL_MACHINE is a "registry hive" root, and "Software\Microsoft" the relative path.
/// </summary>
/// <param name="rootPath">absolute registry path</param>
/// <param name="rootPathWithoutHive">Returns the relative path</param>
/// <param name="registryView">Type of registry you want to see (32-bit, 64-bit, default).</param>
/// <param name="remoteMachineName">Name of a remote machine. User must ensure that caller has sufficient privileges to access the key</param>
/// <returns>"registry hive" root</returns>
public static RegistryKey OpenRegistryHive(string rootPath, out string rootPathWithoutHive, RegistryView registryView, string remoteMachineName = null)
{
rootPathWithoutHive = "";
bool found = false;
foreach (string key in KnownHives.Keys)
{
if (rootPath.StartsWith(key+"\\", StringComparison.OrdinalIgnoreCase))
{
rootPathWithoutHive = rootPath.Substring(key.Length+1);
found = true;
}
if (rootPath.Equals(key, StringComparison.OrdinalIgnoreCase))
{
rootPathWithoutHive = rootPath.Substring(key.Length);
found = true;
}
if (found)
{
if (string.IsNullOrEmpty(remoteMachineName))
{
return RegistryKey.OpenBaseKey(KnownHives[key], registryView);
}
else
{
return RegistryKey.OpenRemoteBaseKey(KnownHives[key], remoteMachineName, registryView);
}
}
}
Trace.TraceWarning("'{0}' is not a well-formed registry path", rootPath);
return null;
}
示例10: ReadFromRegistry
LicenseSourceResult ReadFromRegistry(RegistryView view, string applicationName)
{
try
{
using (var rootKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, view))
using (var registryKey = rootKey.OpenSubKey(keyPath))
{
if (registryKey == null)
{
return ValidateLicense(null, applicationName);
}
var regValue = registryKey.GetValue("License", null);
var licenseText = (regValue is string[])
? string.Join(" ", (string[])regValue)
: (string)regValue;
return ValidateLicense(licenseText, applicationName);
}
}
catch (SecurityException)
{
return new LicenseSourceResult
{
Location = location,
Result = $"Insufficent rights to read license from {location}"
};
}
}
示例11: OpenRemoteBaseKey
public IRegistryKey OpenRemoteBaseKey(
RegistryHive hKey,
string machineName,
RegistryView view
)
{
return new RegistryKeyWrap(RegistryKey.OpenRemoteBaseKey(hKey, machineName, view));
}
示例12: DeleteKey
static void DeleteKey(RegistryHive hive, RegistryView view, string guid)
{
using (RegistryKey key = RegistryKey.OpenBaseKey(hive, view)) {
key.DeleteSubKey("Software\\Classes\\CLSID\\" + guid + "\\ProgId", false);
key.DeleteSubKey("Software\\Classes\\CLSID\\" + guid + "\\InProcServer32", false);
key.DeleteSubKey("Software\\Classes\\CLSID\\" + guid, false);
}
}
示例13: FindRegistryValueUnderKey
private static string FindRegistryValueUnderKey(string registryBaseKeyName, string registryKeyName, RegistryView registryView)
{
using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
{
using (RegistryKey registryKey2 = registryKey.OpenSubKey(registryBaseKeyName))
{
return registryKey2?.GetValue(registryKeyName)?.ToString() ?? string.Empty;
}
}
}
示例14: CreateKeys
static void CreateKeys(RegistryHive hive, RegistryView view, string guid, string libraryId, string classId, string path)
{
using (RegistryKey key = RegistryKey.OpenBaseKey(hive, view)) {
using (RegistryKey subKey = key.CreateSubKey("Software\\Classes\\CLSID\\" + guid))
subKey.SetValue(null, classId + " Class");
using (RegistryKey subKey = key.CreateSubKey("Software\\Classes\\CLSID\\" + guid + "\\InProcServer32"))
subKey.SetValue(null, path);
using (RegistryKey subKey = key.CreateSubKey("Software\\Classes\\CLSID\\" + guid + "\\ProgId"))
subKey.SetValue(null, libraryId + "." + classId);
}
}
示例15: ReadRegistry
static string ReadRegistry(RegistryView view, string keyName, string defaultValue)
{
using (var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, view).OpenSubKey(@"SOFTWARE\ParticularSoftware\ServiceBus"))
{
if (key == null)
{
return defaultValue;
}
return (string) key.GetValue(keyName, defaultValue);
}
}