Here are the examples of the csharp api Microsoft.Win32.RegistryKey.OpenSubKey(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1105 Examples
19
Source : Install.xaml.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
private void RegisterInRegistry()
{
if (!setup.CancellationPending)
{
logger.WriteLog("Writing to registry...");
Invoker.InvokeStatus(progress, txt_log, txt_status, "Creating Registry entries...");
RegistryKey edgeKey = Registry.CurrentUser.OpenSubKey(@"Software\" + GlobalValues.AppName, true);
if (edgeKey == null)
{
edgeKey = Registry.CurrentUser.CreateSubKey(@"Software\" + GlobalValues.AppName);
edgeKey.SetValue("Path", path);
edgeKey.SetValue("Name", path + data);
edgeKey.SetValue("GUID", GlobalValues.AppName);
}
Status = InstallationStatus.REGISTRY_EDITED;
CheckCancellation();
}
}
19
Source : Uninstall.xaml.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
private void RemoveFromRegistry()
{
RegistryKey edgeKey = Registry.CurrentUser.OpenSubKey(@"Software\" + GlobalValues.AppName, false);
string guidPath = edgeKey.GetValue("GUID").ToString();
edgeKey.Close();
Registry.CurrentUser.DeleteSubKey(@"Software\" + GlobalValues.AppName);
Registry.CurrentUser.DeleteSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + guidPath);
}
19
Source : Uninstall.xaml.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
private void RemoveFromRegistry()
{
RegistryKey edgeKey = Registry.CurrentUser.OpenSubKey(@"Software\" + GlobalValues.AppName, false);
string guidPath = edgeKey.GetValue("GUID").ToString();
edgeKey.Close();
Registry.CurrentUser.DeleteSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + guidPath);
}
19
Source : RegistryManager.cs
with MIT License
from BlackDragonBE
with MIT License
from BlackDragonBE
public static bool LogonRegistryKeyExists()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
return key.GetValue(Shared.APP_NAME_VALUE) != null;
}
19
Source : RegistryManager.cs
with MIT License
from BlackDragonBE
with MIT License
from BlackDragonBE
public static string GetLogonProfileKeyValue()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
string[] valueArray = key.GetValue(Shared.APP_NAME_VALUE).ToString().Split(' ');
//MessageBox.Show(valueArray[valueArray.Length - 1]);//todo: debug, remove
return valueArray[valueArray.Length-1]; // Get profile name by extracting name after last space
}
19
Source : UninstallEntry.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public void CreateUninstaller(double estimatedSize)
{
try
{
try
{
if (Registry.CurrentUser.OpenSubKey(UninstallRegKeyPath) == null)
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
catch
{
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
UninstallRegKeyPath, true))
{
if (parent == null)
{
throw new Exception("Uninstall registry key not found.");
}
RegistryKey key = null;
try
{
key = parent.OpenSubKey(GlobalValues.AppName, true) ??
parent.CreateSubKey(GlobalValues.AppName);
if (key == null)
{
throw new Exception(string.Format("Unable to create uninstaller \"{0}\\{1}\"", UninstallRegKeyPath, GlobalValues.AppName));
}
replacedembly asm = GetType().replacedembly;
Version v = asm.GetName().Version;
string exe = GlobalValues.InstallationPath + GlobalValues.AppName + ".exe";
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("HelpLink", "https://osu.ppy.sh/forum/t/756318");
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayName", GlobalValues.AppName);
key.SetValue("DisplayVersion", v.ToString(2));
key.SetValue("EstimatedSize", estimatedSize, RegistryValueKind.DWord);
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("NoRepair", 1, RegistryValueKind.DWord);
key.SetValue("NoModify", 1, RegistryValueKind.DWord);
key.SetValue("Publisher", "BlackTasty");
key.SetValue("URLInfoAbout", "");
key.SetValue("InstallLocation", GlobalValues.InstallationPath);
key.SetValue("UninstallString", GlobalValues.InstallationPath + "uninstall.exe");
}
finally
{
if (key != null)
{
key.Close();
}
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. " +
"The application has been fully installed but can only be uninstalled manually through " +
"deleting the files located in " + GlobalValues.InstallationPath + ".",
ex);
}
}
19
Source : UninstallEntry.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public void CreateUninstaller(double estimatedSize)
{
try
{
try
{
if (Registry.CurrentUser.OpenSubKey(UninstallRegKeyPath) == null)
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
catch
{
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
UninstallRegKeyPath, true))
{
if (parent == null)
{
throw new Exception("Uninstall registry key not found.");
}
RegistryKey key = null;
try
{
key = parent.OpenSubKey(GlobalValues.AppName, true) ??
parent.CreateSubKey(GlobalValues.AppName);
if (key == null)
{
throw new Exception(string.Format("Unable to create uninstaller \"{0}\\{1}\"", UninstallRegKeyPath, GlobalValues.AppName));
}
replacedembly asm = GetType().replacedembly;
Version v = asm.GetName().Version;
string exe = GlobalValues.InstallationPath + GlobalValues.AppName + ".exe";
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("HelpLink", "https://osu.ppy.sh/forum/t/756318");
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayName", GlobalValues.AppName);
key.SetValue("DisplayVersion", v.ToString(2));
key.SetValue("EstimatedSize", estimatedSize, RegistryValueKind.DWord);
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("NoRepair", 1, RegistryValueKind.DWord);
key.SetValue("NoModify", 1, RegistryValueKind.DWord);
key.SetValue("Publisher", "BlackTasty");
key.SetValue("URLInfoAbout", "");
key.SetValue("InstallLocation", GlobalValues.InstallationPath);
key.SetValue("UninstallString", GlobalValues.InstallationPath + "uninstall.exe");
}
finally
{
if (key != null)
{
key.Close();
}
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. " +
"The application has been fully installed but can only be uninstalled manually through " +
"deleting the files located in " + GlobalValues.InstallationPath + ".",
ex);
}
}
19
Source : MainWindow.xaml.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
private void next_Click(object sender, RoutedEventArgs e)
{
switch (activeControl.Name)
{
case "agreement":
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\" + GlobalValues.AppName, false);
IsUpgrade = key != null;
if (IsUpgrade)
FadeControls(agreement, appInstalled, true, true);
else
FadeControls(agreement, components, true, true);
break;
case "appInstalled":
if (appInstalled.rb_uninstall.IsChecked == true)
{
FadeControls(appInstalled, uninstall, false, false);
uninstall.RegisterParent(this);
}
else
FadeControls(appInstalled, components, true, true);
break;
case "components":
FadeControls(components, install, false, false);
install.EstimatedSize = (components.DataContext as ComponentsViewModel).SpaceRequired;
install.RegisterParent(this);
break;
case "install":
if (!install.Aborted)
FadeControls(install, finished, true, false, true);
else
FadeControls(install, aborted, true, false, true);
break;
case "uninstall":
FadeControls(uninstall, finishedUninstall, true, false, true);
break;
case "aborted":
Close();
break;
case "finished":
if (finished.cb_runAfter.IsChecked == true)
{
Process.Start(GlobalValues.InstallationPath + GlobalValues.AppName + ".exe");
}
Close();
break;
case "finishedUninstall":
Close();
break;
}
}
19
Source : UninstallEntry.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public void CreateUninstaller(double estimatedSize)
{
try
{
try
{
if (Registry.CurrentUser.OpenSubKey(UninstallRegKeyPath) == null)
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
catch
{
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
UninstallRegKeyPath, true))
{
if (parent == null)
{
throw new Exception("Uninstall registry key not found.");
}
RegistryKey key = null;
try
{
key = parent.OpenSubKey(GlobalValues.AppName, true) ??
parent.CreateSubKey(GlobalValues.AppName);
if (key == null)
{
throw new Exception(string.Format("Unable to create uninstaller \"{0}\\{1}\"", UninstallRegKeyPath, GlobalValues.AppName));
}
replacedembly asm = GetType().replacedembly;
Version v = asm.GetName().Version;
string exe = GlobalValues.InstallationPath + GlobalValues.AppName + ".exe";
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("HelpLink", "https://osu.ppy.sh/forum/t/756318");
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayName", GlobalValues.AppName);
key.SetValue("DisplayVersion", v.ToString(2));
key.SetValue("EstimatedSize", estimatedSize, RegistryValueKind.DWord);
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("NoRepair", 1, RegistryValueKind.DWord);
key.SetValue("NoModify", 1, RegistryValueKind.DWord);
key.SetValue("Publisher", "BlackTasty");
key.SetValue("URLInfoAbout", "");
key.SetValue("InstallLocation", GlobalValues.InstallationPath);
key.SetValue("UninstallString", GlobalValues.InstallationPath + "uninstall.exe");
}
finally
{
if (key != null)
{
key.Close();
}
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. The application has been fully installed but can only be uninstalled manually through deleting the files located in " + GlobalValues.InstallationPath + ".",
ex);
}
}
19
Source : UninstallEntry.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public void CreateUninstaller(double estimatedSize)
{
try
{
try
{
if (Registry.CurrentUser.OpenSubKey(UninstallRegKeyPath) == null)
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
catch
{
Registry.CurrentUser.CreateSubKey(UninstallRegKeyPath);
}
using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
UninstallRegKeyPath, true))
{
if (parent == null)
{
throw new Exception("Uninstall registry key not found.");
}
RegistryKey key = null;
try
{
key = parent.OpenSubKey(GlobalValues.AppName, true) ??
parent.CreateSubKey(GlobalValues.AppName);
if (key == null)
{
throw new Exception(string.Format("Unable to create uninstaller \"{0}\\{1}\"", UninstallRegKeyPath, GlobalValues.AppName));
}
replacedembly asm = GetType().replacedembly;
Version v = asm.GetName().Version;
string exe = GlobalValues.InstallationPath + GlobalValues.AppName + ".exe";
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("HelpLink", "https://osu.ppy.sh/forum/t/756318");
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayName", GlobalValues.AppName);
key.SetValue("DisplayVersion", v.ToString(2));
key.SetValue("EstimatedSize", estimatedSize, RegistryValueKind.DWord);
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("NoRepair", 1, RegistryValueKind.DWord);
key.SetValue("NoModify", 1, RegistryValueKind.DWord);
key.SetValue("Publisher", "BlackTasty");
key.SetValue("URLInfoAbout", "");
key.SetValue("InstallLocation", GlobalValues.InstallationPath);
key.SetValue("UninstallString", GlobalValues.InstallationPath + "uninstall.exe");
}
finally
{
if (key != null)
{
key.Close();
}
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. The application has been fully installed but can only be uninstalled manually through deleting the files located in " + GlobalValues.InstallationPath + ".",
ex);
}
}
19
Source : Helper.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public static string FindOsuInstallation()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Clreplacedes\\osu\\DefaultIcon");
if (key != null)
{
string path;
path = key.GetValue("").ToString();
path = path.Replace("\"", "");
path = path.Remove(path.LastIndexOf('\\')) + "\\Skins";
if (Directory.Exists(path))
{
return path;
}
else
{
return null;
}
}
else
{
return null;
}
}
19
Source : Helper.cs
with GNU General Public License v2.0
from BlackTasty
with GNU General Public License v2.0
from BlackTasty
public static bool IsOsuInstalled()
{
return Registry.LocalMachine.OpenSubKey("SOFTWARE\\Clreplacedes\\osu\\DefaultIcon") != null;
}
19
Source : RegistryEx.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
public static void CopyTo(this RegistryKey srcKey, RegistryKey dstKey)
{
foreach(string name in srcKey.GetValueNames())
{
dstKey.SetValue(name, srcKey.GetValue(name), srcKey.GetValueKind(name));
}
foreach(string name in srcKey.GetSubKeyNames())
{
using(RegistryKey srcSubKey = srcKey.OpenSubKey(name))
using(RegistryKey dstSubKey = dstKey.CreateSubKey(name, true))
srcSubKey.CopyTo(dstSubKey);
}
}
19
Source : FileExtension.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
public static string GetOpenMode(string extension)
{
if(string.IsNullOrEmpty(extension)) return null;
string mode;
bool CheckMode()
{
if(mode.IsNullOrWhiteSpace()) return false;
if(mode.Length > 255) return false;
if(mode.ToLower().StartsWith(@"applications\")) return false;
using(RegistryKey root = Registry.ClreplacedesRoot)
using(RegistryKey key = root.OpenSubKey(mode))
{
return key != null;
}
}
mode = Registry.GetValue($@"{FILEEXTSPATH}\{extension}\UserChoice", "ProgId", null)?.ToString();
if(CheckMode()) return mode;
mode = Registry.GetValue($@"{HKLMCLreplacedES}\{extension}", "", null)?.ToString();
if(CheckMode()) return mode;
mode = Registry.GetValue($@"{HKCRCLreplacedES}\{extension}", "", null)?.ToString();
if(CheckMode()) return mode;
return null;
}
19
Source : IEList.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
private void LoadIEItems()
{
List<string> names = new List<string>();
using(RegistryKey ieKey = RegistryEx.GetRegistryKey(IEPath))
{
if(ieKey == null) return;
foreach(string part in IEItem.MeParts)
{
using(RegistryKey meKey = ieKey.OpenSubKey(part))
{
if(meKey == null) continue;
foreach(string keyName in meKey.GetSubKeyNames())
{
if(names.Contains(keyName, StringComparer.OrdinalIgnoreCase)) continue;
using(RegistryKey key = meKey.OpenSubKey(keyName))
{
if(!string.IsNullOrEmpty(key.GetValue("")?.ToString()))
{
this.AddItem(new IEItem(key.Name));
names.Add(keyName);
}
}
}
}
}
}
}
19
Source : OpenWithList.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
private void LoadOpenWithItems()
{
using(RegistryKey root = Registry.ClreplacedesRoot)
using(RegistryKey appKey = root.OpenSubKey("Applications"))
{
foreach(string appName in appKey.GetSubKeyNames())
{
if(!appName.Contains('.')) continue;//需要为有扩展名的文件名
using(RegistryKey shellKey = appKey.OpenSubKey($@"{appName}\shell"))
{
if(shellKey == null) continue;
List<string> names = shellKey.GetSubKeyNames().ToList();
if(names.Contains("open", StringComparer.OrdinalIgnoreCase)) names.Insert(0, "open");
string keyName = names.Find(name =>
{
using(RegistryKey cmdKey = shellKey.OpenSubKey(name))
return cmdKey.GetValue("NeverDefault") == null;
});
if(keyName == null) continue;
using(RegistryKey commandKey = shellKey.OpenSubKey($@"{keyName}\command"))
{
string command = commandKey?.GetValue("")?.ToString();
if(ObjectPath.ExtractFilePath(command) != null)
this.AddItem(new OpenWithItem(commandKey.Name));
}
}
}
}
}
19
Source : ShellExItem.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
public static Dictionary<string, Guid> GetPathAndGuids(string shellExPath, bool isDragDrop = false)
{
Dictionary<string, Guid> dic = new Dictionary<string, Guid>();
string[] parts = isDragDrop ? DdhParts : CmhParts;
foreach(string part in parts)
{
using(RegistryKey cmKey = RegistryEx.GetRegistryKey($@"{shellExPath}\{part}"))
{
if(cmKey == null) continue;
foreach(string keyName in cmKey.GetSubKeyNames())
{
try
{
using(RegistryKey key = cmKey.OpenSubKey(keyName))
{
if(!GuidEx.TryParse(key.GetValue("")?.ToString(), out Guid guid))
GuidEx.TryParse(keyName, out guid);
if(!guid.Equals(Guid.Empty))
dic.Add(key.Name, guid);
}
}
catch { continue; }
}
}
}
return dic;
}
19
Source : ShellNewList.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
private void LoadItems(List<string> extensions)
{
foreach(string extension in ShellNewItem.UnableSortExtensions)
{
if(extensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
extensions.Remove(extension);
extensions.Insert(0, extension);
}
}
using(RegistryKey root = Registry.ClreplacedesRoot)
{
foreach(string extension in extensions)
{
using(RegistryKey extKey = root.OpenSubKey(extension))
{
string defalutOpenMode = extKey?.GetValue("")?.ToString();
if(string.IsNullOrEmpty(defalutOpenMode) || defalutOpenMode.Length > 255) continue;
using(RegistryKey openModeKey = root.OpenSubKey(defalutOpenMode))
{
if(openModeKey == null) continue;
string value1 = openModeKey.GetValue("FriendlyTypeName")?.ToString();
string value2 = openModeKey.GetValue("")?.ToString();
value1 = ResourceString.GetDirectString(value1);
if(value1.IsNullOrWhiteSpace() && value2.IsNullOrWhiteSpace()) continue;
}
using(RegistryKey tKey = extKey.OpenSubKey(defalutOpenMode))
{
foreach(string part in ShellNewItem.SnParts)
{
string snPart = part;
if(tKey != null) snPart = $@"{defalutOpenMode}\{snPart}";
using(RegistryKey snKey = extKey.OpenSubKey(snPart))
{
if(ShellNewItem.EffectValueNames.Any(valueName => snKey?.GetValue(valueName) != null))
{
ShellNewItem item = new ShellNewItem(this, snKey.Name);
if(item.BeforeSeparator)
{
int index2 = this.GereplacedemIndex(Separator);
this.Inserreplacedem(item, index2);
}
else
{
this.AddItem(item);
}
break;
}
}
}
}
}
}
}
}
19
Source : GuidInfo.cs
with MIT License
from BluePointLilac
with MIT License
from BluePointLilac
public static string GetFilePath(Guid guid)
{
string filePath = null;
if(guid.Equals(Guid.Empty)) return filePath;
if(FilePathDic.ContainsKey(guid)) filePath = FilePathDic[guid];
else
{
string uwpName = GetUwpName(guid);
if(!string.IsNullOrEmpty(uwpName))
{
filePath = UwpHelper.GetFilePath(uwpName, guid);
}
else
{
foreach(string clsidPath in ClsidPaths)
{
using(RegistryKey guidKey = RegistryEx.GetRegistryKey($@"{clsidPath}\{guid:B}"))
{
if(guidKey == null) continue;
foreach(string keyName in new[] { "InprocServer32", "LocalServer32" })
{
using(RegistryKey key = guidKey.OpenSubKey(keyName))
{
if(key == null) continue;
string value1 = key.GetValue("CodeBase")?.ToString().Replace("file:///", "").Replace('/', '\\');
if(File.Exists(value1))
{
filePath = value1; break;
}
string value2 = key.GetValue("")?.ToString();
value2 = ObjectPath.ExtractFilePath(value2);
if(File.Exists(value2))
{
filePath = value2; break;
}
}
}
if(File.Exists(filePath))
{
if(ClsidPathDic.ContainsKey(guid)) ClsidPathDic[guid] = guidKey.Name;
else ClsidPathDic.Add(guid, guidKey.Name);
break;
}
}
}
}
FilePathDic.Add(guid, filePath);
}
return filePath;
}
19
Source : NetworkInterface.cs
with GNU General Public License v3.0
from BornToBeRoot
with GNU General Public License v3.0
from BornToBeRoot
public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
{
var listNetworkInterfaceInfo = new List<NetworkInterfaceInfo>();
foreach (var networkInterface in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
// NetworkInterfaceType 53 is proprietary virtual/internal interface
// https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-interface-types
if (networkInterface.NetworkInterfaceType != NetworkInterfaceType.Ethernet && networkInterface.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && (int)networkInterface.NetworkInterfaceType != 53)
continue;
var listIPv4Address = new List<Tuple<IPAddress, IPAddress>>();
var listIPv6AddressLinkLocal = new List<IPAddress>();
var listIPv6Address = new List<IPAddress>();
var dhcpLeaseObtained = new DateTime();
var dhcpLeaseExpires = new DateTime();
var ipProperties = networkInterface.GetIPProperties();
foreach (var unicastIPAddrInfo in ipProperties.UnicastAddresses)
{
switch (unicastIPAddrInfo.Address.AddressFamily)
{
case AddressFamily.InterNetwork:
listIPv4Address.Add(new Tuple<IPAddress, IPAddress>(unicastIPAddrInfo.Address, unicastIPAddrInfo.IPv4Mask));
dhcpLeaseExpires = (DateTime.UtcNow + TimeSpan.FromSeconds(unicastIPAddrInfo.AddressPreferredLifetime)).ToLocalTime();
dhcpLeaseObtained = (DateTime.UtcNow + TimeSpan.FromSeconds(unicastIPAddrInfo.AddressValidLifetime) - TimeSpan.FromSeconds(unicastIPAddrInfo.DhcpLeaseLifetime)).ToLocalTime();
break;
case AddressFamily.InterNetworkV6 when unicastIPAddrInfo.Address.IsIPv6LinkLocal:
listIPv6AddressLinkLocal.Add(unicastIPAddrInfo.Address);
break;
case AddressFamily.InterNetworkV6:
listIPv6Address.Add(unicastIPAddrInfo.Address);
break;
}
}
var listIPv4Gateway = new List<IPAddress>();
var listIPv6Gateway = new List<IPAddress>();
foreach (var gatewayIPAddrInfo in ipProperties.GatewayAddresses)
{
switch (gatewayIPAddrInfo.Address.AddressFamily)
{
case AddressFamily.InterNetwork:
listIPv4Gateway.Add(gatewayIPAddrInfo.Address);
break;
case AddressFamily.InterNetworkV6:
listIPv6Gateway.Add(gatewayIPAddrInfo.Address);
break;
}
}
var listDhcpServer = new List<IPAddress>();
foreach (var dhcpServerIPAddress in ipProperties.DhcpServerAddresses)
{
if (dhcpServerIPAddress.AddressFamily == AddressFamily.InterNetwork)
listDhcpServer.Add(dhcpServerIPAddress);
}
// Check if autoconfiguration for DNS is enabled (only via registry key)
var nameServerKey = Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{networkInterface.Id}");
var dnsAutoconfigurationEnabled = nameServerKey?.GetValue("NameServer") != null && string.IsNullOrEmpty(nameServerKey.GetValue("NameServer").ToString());
var listDNSServer = new List<IPAddress>();
foreach (var dnsServerIPAddress in ipProperties.DnsAddresses)
{
listDNSServer.Add(dnsServerIPAddress);
}
// Check if IPv4 protocol is available
var ipv4ProtocolAvailable = true;
IPv4InterfaceProperties ipv4Properties = null;
try
{
ipv4Properties = ipProperties.GetIPv4Properties();
}
catch (NetworkInformationException)
{
ipv4ProtocolAvailable = false;
}
// Check if IPv6 protocol is available
var ipv6ProtocolAvailable = true;
IPv6InterfaceProperties ipv6Properties = null;
try
{
ipv6Properties = ipProperties.GetIPv6Properties();
}
catch (NetworkInformationException)
{
ipv6ProtocolAvailable = false;
}
listNetworkInterfaceInfo.Add(new NetworkInterfaceInfo
{
Id = networkInterface.Id,
Name = networkInterface.Name,
Description = networkInterface.Description,
Type = networkInterface.NetworkInterfaceType.ToString(),
PhysicalAddress = networkInterface.GetPhysicalAddress(),
Status = networkInterface.OperationalStatus,
IsOperational = networkInterface.OperationalStatus == OperationalStatus.Up,
Speed = networkInterface.Speed,
IPv4ProtocolAvailable = ipv4ProtocolAvailable,
IPv4Address = listIPv4Address.ToArray(),
IPv4Gateway = listIPv4Gateway.ToArray(),
DhcpEnabled = ipv4Properties != null && ipv4Properties.IsDhcpEnabled,
DhcpServer = listDhcpServer.ToArray(),
DhcpLeaseObtained = dhcpLeaseObtained,
DhcpLeaseExpires = dhcpLeaseExpires,
IPv6ProtocolAvailable = ipv6ProtocolAvailable,
IPv6AddressLinkLocal = listIPv6AddressLinkLocal.ToArray(),
IPv6Address = listIPv6Address.ToArray(),
IPv6Gateway = listIPv6Gateway.ToArray(),
DNSAutoconfigurationEnabled = dnsAutoconfigurationEnabled,
DNSSuffix = ipProperties.DnsSuffix,
DNSServer = listDNSServer.ToArray()
});
}
return listNetworkInterfaceInfo;
}
19
Source : ExplorerIntegration.cs
with MIT License
from botman99
with MIT License
from botman99
public bool IsEnabled(string where)
{
if( where == "here" )
{
string regPath = string.Format(@"SOFTWARE\Clreplacedes\Directory\Background\shell\Grepy2");
try
{
return Registry.LocalMachine.OpenSubKey(regPath) != null;
}
catch( UnauthorizedAccessException )
{
return false;
}
}
else
{
string regPath = string.Format(@"{0}\shell\Grepy2", where);
try
{
return Registry.ClreplacedesRoot.OpenSubKey(regPath) != null;
}
catch( UnauthorizedAccessException )
{
return false;
}
}
}
19
Source : Window1.xaml.cs
with MIT License
from bstollnitz
with MIT License
from bstollnitz
public void PopulateSubKeys()
{
try
{
string[] subKeyNames = this.key.GetSubKeyNames();
for (int i = 0; i < subKeyNames.Length; i++)
{
this.subKeys.Add(new RegistryKeyHolder1(this.key.OpenSubKey(subKeyNames[i])));
}
}
catch (SecurityException se)
{
System.Console.WriteLine(se.Message);
}
}
19
Source : Window1.xaml.cs
with MIT License
from bstollnitz
with MIT License
from bstollnitz
public int PopulateSubKeys()
{
try
{
string[] subKeyNames = this.key.GetSubKeyNames();
for (int i = 0; i < subKeyNames.Length; i++)
{
this.subKeys.Add(new RegistryKeyHolder2(this.key.OpenSubKey(subKeyNames[i])));
}
return subKeyNames.Length;
}
catch (SecurityException se)
{
System.Console.WriteLine(se.Message);
return 0;
}
}
19
Source : Window1.xaml.cs
with MIT License
from bstollnitz
with MIT License
from bstollnitz
public void PopulateSubKeys(RegistryKeyHolder3 parentKeyHolder)
{
int indexParentKey = this.allKeys.IndexOf(parentKeyHolder);
if (indexParentKey == this.allKeys.Count - 1 || this.allKeys[indexParentKey + 1].Level <= parentKeyHolder.Level)
{
string[] subKeyNames = parentKeyHolder.Key.GetSubKeyNames();
for (int i = 0; i < subKeyNames.Length; i++)
{
RegistryKeyHolder3 childKeyHolder = new RegistryKeyHolder3(parentKeyHolder.Key.OpenSubKey(subKeyNames[i]), parentKeyHolder.Level + 1);
childKeyHolder.PropertyChanged += new PropertyChangedEventHandler(KeyHolder_PropertyChanged);
allKeys.Insert(indexParentKey + i + 1, childKeyHolder);
this.DataItemsCount++;
}
}
}
19
Source : Form1.cs
with MIT License
from bugworm
with MIT License
from bugworm
private void FindTPSSteam()
{
// get install path of Borderlands The PreSequel
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 261640");
if (key != null)
{
btpsil = key.GetValue("InstallLocation") as string;
}
else
{
key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 261640");
if (key != null)
{
btpsil = key.GetValue("InstallLocation") as string;
}
}
// else key could not be found
}
19
Source : Form1.cs
with MIT License
from bugworm
with MIT License
from bugworm
private void FindBL2Steam()
{
// get install path of Borderlands 2
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 49520");
if (key != null)
{
b2il = key.GetValue("InstallLocation") as string;
}
else
{
key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 49520");
if (key != null)
{
b2il = key.GetValue("InstallLocation") as string;
}
}
// else key could not be found
}
19
Source : Utility.cs
with The Unlicense
from BuIlDaLiBlE
with The Unlicense
from BuIlDaLiBlE
public static string GetWindowsVersion()
{
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string name = "Windows";
string build = "0";
string version = string.Empty;
string revision = "0";
try
{
var value = key.GetValue("ProductName").ToString();
if(!string.IsNullOrEmpty(value))
{
name = value;
}
}catch{}
try
{
var value = key.GetValue("CurrentBuild").ToString();
if(!string.IsNullOrEmpty(value))
{
build = value;
}
}catch{}
try
{
var value = key.GetValue("DisplayVersion").ToString();
if(!string.IsNullOrEmpty(value))
{
version = value;
}
}catch{}
try
{
var value = key.GetValue("UBR").ToString();
if(!string.IsNullOrEmpty(value))
{
revision = value;
}
}catch{}
if(Environment.OSVersion.Version.Major == 10)
{
if(!string.IsNullOrEmpty(version))
return $"{name} (Version {version}, Build {build}.{revision})";
else
return $"{name} (Build {build}.{revision})";
}
else
{
return $"{name} (Build {build})";
}
}
19
Source : MainWindow.xaml.cs
with MIT License
from builtbybel
with MIT License
from builtbybel
private void CheckAU()
{
RegistryKey RegHKLM = Registry.LocalMachine;
RegistryKey updateRegHKLM;
if (RegHKLM.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU") != null)
{
updateRegHKLM = RegHKLM.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU");
if (updateRegHKLM.GetValueNames().Contains("AUOptions"))
{
if ((Int32)updateRegHKLM.GetValue("AUOptions") == 2) { _checkAU.IsChecked = true; _checkAU.Content = "*Automatic updates on this device are turned off."; }
else { _checkAU.IsChecked = false; _checkAU.Content = "*Automatic updates on this device are turned on."; }
}
updateRegHKLM.Close();
}
}
19
Source : OS.cs
with MIT License
from builtbybel
with MIT License
from builtbybel
public bool IsWin11()
{
ComputerName = Environment.MachineName;
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
int osbuild = Convert.ToInt32(key.GetValue("CurrentBuildNumber"));
if (osbuild >= 22000)
{
return true;
}
}
catch { }
return false;
}
19
Source : OS.cs
with MIT License
from builtbybel
with MIT License
from builtbybel
public string GetOS()
{
ComputerName = Environment.MachineName;
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
int osbuild = Convert.ToInt32(key.GetValue("CurrentBuildNumber"));
if (osbuild >= 22000)
{
return ("Windows 11 aka Sun Valley");
}
else return (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", "");
}
19
Source : OS.cs
with MIT License
from builtbybel
with MIT License
from builtbybel
public string GetVersion()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
var UBR = key.GetValue("UBR").ToString();
var CurrentBuild = key.GetValue("CurrentBuild").ToString();
string version = CurrentBuild + "." + UBR;
return "Build " + version;
}
19
Source : FirstBootMenu.cs
with GNU General Public License v2.0
from Caeden117
with GNU General Public License v2.0
from Caeden117
private string TryOculusStoreLibraryLocations()
{
var libraryKey = Registry.CurrentUser.OpenSubKey("Software\\Oculus VR, LLC\\Oculus\\Libraries");
if (libraryKey == null) return "";
var subKeys = libraryKey.GetSubKeyNames();
foreach (var subKeyName in subKeys)
{
var originalPath = libraryKey.OpenSubKey(subKeyName).GetValue("OriginalPath");
if (originalPath != null && string.IsNullOrEmpty((string)originalPath)) continue;
var installPath = Path.Combine((string)originalPath, "Software", oculusStoreBeatSaberFolderName);
if (Directory.Exists(installPath)) return installPath;
}
return "";
}
19
Source : RegistryKeyExtensions.cs
with Apache License 2.0
from cairoshell
with Apache License 2.0
from cairoshell
public static T GetSubKeyValue<T>(this RegistryKey key, string subKey, string valueName, T defaultValue = default)
{
if (key == null)
return defaultValue;
if (string.IsNullOrWhiteSpace(subKey))
return defaultValue;
if (string.IsNullOrWhiteSpace(valueName))
return defaultValue;
var reg = key.OpenSubKey(subKey);
if (reg == null)
return defaultValue;
return reg.GetValue<T>(valueName, defaultValue);
}
19
Source : StartupRunner.cs
with Apache License 2.0
from cairoshell
with Apache License 2.0
from cairoshell
private List<StartupEntry> GetAppsFromRegistryKey(StartupLocation location)
{
RegistryKey[] roots = ScopeToRoots(location.Scope);
List<StartupEntry> startupApps = new List<StartupEntry>();
foreach (var root in roots)
{
bool isRunOnce = location.Location.Contains("RunOnce");
try
{
if (isRunOnce && root == Registry.LocalMachine)
continue; // skip HKLM RunOnce since we cannot delete these items, and would run them each startup
RegistryKey registryKey =
root.OpenSubKey(location.Location, root == Registry.CurrentUser); // open as writeable if HKCU
if (registryKey != null && registryKey.ValueCount > 0)
{
// get list of disallowed entries
List<string> disallowedItems = GetDisallowedItems(location, root == Registry.LocalMachine ? StartupEntryScope.Machine : StartupEntryScope.User);
// add items from registry key
foreach (var valueName in registryKey.GetValueNames())
{
// only add items that are not disabled
if (!disallowedItems.Contains(valueName))
{
startupApps.Add(new StartupEntry
{
Location = location,
Path = ((string)registryKey.GetValue(valueName)).Replace("\"", "")
});
// if this is a runonce key, remove the value after we grab it
if (isRunOnce)
{
try
{
registryKey.DeleteValue(valueName);
}
catch
{
ShellLogger.Warning($"StartupRunner: Unable to delete RunOnce startup item {valueName}");
}
}
}
}
}
// close key when finished
registryKey?.Close();
}
catch
{
ShellLogger.Warning($"StartupRunner: Unable to load startup items from registry key {location.Location}");
}
}
return startupApps;
}
19
Source : StartupRunner.cs
with Apache License 2.0
from cairoshell
with Apache License 2.0
from cairoshell
private List<string> GetDisallowedItems(StartupLocation location, StartupEntryScope? overrideScope = null)
{
List<string> disallowedApps = new List<string>();
if (!string.IsNullOrEmpty(location.ApprovedLocation))
{
StartupEntryScope scope = overrideScope ?? location.Scope;
RegistryKey[] roots = ScopeToRoots(scope);
foreach (var root in roots)
{
try
{
RegistryKey registryKey =
root.OpenSubKey(location.ApprovedLocation, false);
if (registryKey != null && registryKey.ValueCount > 0)
{
foreach (var valueName in registryKey.GetValueNames())
{
if (((byte[])registryKey.GetValue(valueName))[0] % 2 != 0) // if value is odd number, item is disabled
{
disallowedApps.Add(valueName);
ShellLogger.Debug($"StartupRunner: Skipping disabled entry: {valueName}");
}
}
}
// close key when finished
registryKey?.Close();
}
catch
{
ShellLogger.Warning($"StartupRunner: Unable to load allowed startup items list from registry key {location.ApprovedLocation}");
}
}
}
return disallowedApps;
}
19
Source : SoundHelper.cs
with Apache License 2.0
from cairoshell
with Apache License 2.0
from cairoshell
public static bool PlaySystemSound(string app, string name)
{
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey($"{SYSTEM_SOUND_ROOT_KEY}\\{app}\\{name}\\.Current"))
{
if (key == null)
{
ShellLogger.Error($"SoundHelper: Unable to find sound {name} for app {app}");
return false;
}
if (key.GetValue(null) is string soundFileName)
{
if (string.IsNullOrEmpty(soundFileName))
{
ShellLogger.Error($"SoundHelper: Missing file for sound {name} for app {app}");
return false;
}
return PlaySound(soundFileName, IntPtr.Zero, (uint)(SND_ASYNC | SND_FILENAME | SND_SYSTEM));
}
else
{
ShellLogger.Error($"SoundHelper: Missing file for sound {name} for app {app}");
return false;
}
}
}
catch (Exception e)
{
ShellLogger.Error($"SoundHelper: Unable to play sound {name} for app {app}: {e.Message}");
return false;
}
}
19
Source : Program.cs
with MIT License
from carloscds
with MIT License
from carloscds
public static string DotNetVersion()
{
RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full");
if (ndpKey != null)
{
int value = (int)(ndpKey.GetValue("Release") ?? 0);
if (value >= 528040)
return".NET Framework 4.8";
if (value >= 461808)
return".NET Framework 4.7.2";
if (value >= 461308)
return".NET Framework 4.7.1";
if (value >= 460798)
return".NET Framework 4.7";
if (value >= 394802)
return".NET Framework 4.6.2";
if (value >= 394254)
return".NET Framework 4.6.1";
if (value >= 393295)
return".NET Framework 4.6";
if (value >= 379893)
return".NET Framework 4.5.2";
if (value >= 378675)
return".NET Framework 4.5.1";
if (value >= 378389)
return".NET Framework 4.5";
}
return "No .NET Framework detected.";
}
19
Source : Program.cs
with GNU General Public License v3.0
from Ceiridge
with GNU General Public License v3.0
from Ceiridge
private static void LoadChromeExePaths() {
using (RegistryKey exeKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Ceiridge\ChromePatcher\ChromeExes")) {
foreach (string name in exeKey.GetValueNames()) {
if (name.Length >= 1) {
string value = exeKey.GetValue(name, "").ToString();
if (value.Length > 5) {
ChromeExeFilePaths.Add(value);
}
}
}
}
}
19
Source : Sec_Checks.cs
with GNU Affero General Public License v3.0
from ceramicskate0
with GNU Affero General Public License v3.0
from ceramicskate0
private static bool Check_Windows_Event_Log_Retention_Policy()
{
List<EventLog> eventLogs = EventLog.GetEventLogs().ToList();
for (int x = 0; x < eventLogs.Count; ++x)
{
if (eventLogs.Any(s => eventLogs.ElementAt(x).Log.ToLower().IndexOf(s.Log.ToLower(), StringComparison.OrdinalIgnoreCase) > 0))
{
RegistryKey regEventLog = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Services\\EventLog\\" + eventLogs.ElementAt(x).Log);
if (regEventLog != null)
{
Object RegKeyFileAttrib = regEventLog.GetValue("File");
if (RegKeyFileAttrib != null)
{
switch (eventLogs.ElementAt(x).OverflowAction)
{
case OverflowAction.OverwriteOlder:
LOG_SEC_CHECK_Fail("Check_Windows_Event_Log_Retention_Policy() " + eventLogs.ElementAt(x).LogDisplayName + " is set to not overwire only logs older than " + eventLogs.ElementAt(x).MinimumRetentionDays.ToString());
return true;
case OverflowAction.DoNotOverwrite:
LOG_SEC_CHECK_Fail("Check_Windows_Event_Log_Retention_Policy() " + eventLogs.ElementAt(x).LogDisplayName + " is set to not overwire the oldest event log");
return true;
}
}
else
{
LOG_SEC_CHECK_Fail("Check_Windows_Event_Log_Retention_Policy() "+ eventLogs.ElementAt(x).LogDisplayName + " \"File\" reg attrib does not exist and it should");
return false;
}
}
}
}
return true;
}
19
Source : Sec_Checks.cs
with GNU Affero General Public License v3.0
from ceramicskate0
with GNU Affero General Public License v3.0
from ceramicskate0
private static bool Check_EventLog_Service_Reg_Keys()
{
List<string> RegKeys = new List<string>
{
@"System\CurrentControlSet\Services\Eventlog",
@"SYSTEM\CurrentControlSet\Control\WMI\Autologger"
};
for (int x = 0; x < RegKeys.Count; ++x)
{
try
{
RegistryKey reg = Registry.LocalMachine.OpenSubKey(RegKeys.ElementAt(x));
if (reg == null)
{
return false;
}
}
catch (Exception e)
{
LOG_SEC_CHECK_Fail("FAILED Security Check Registry " + e.Message.ToString());
return false;
}
}
return true;
}
19
Source : EnvironmentHelpers.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
public static bool IsFileTypereplacedociated(string fileExtension)
{
// Source article: https://edi.wang/post/2019/3/4/read-and-write-windows-registry-in-net-core
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw new InvalidOperationException("Operation only supported on windows.");
}
fileExtension = fileExtension.TrimStart('.'); // Remove . if added by the caller.
using (RegistryKey key = Registry.ClreplacedesRoot.OpenSubKey($".{fileExtension}"))
{
if (key != null)
{
object val = key.GetValue(null); // Read the (Default) value.
if (val != null)
{
return true;
}
}
}
return false;
}
19
Source : Browser.cs
with MIT License
from charleszhang97
with MIT License
from charleszhang97
public bool OpenDefaultBrowser(string url)
{
RegistryKey key = null;
try
{
// 方法1
//从注册表中读取默认浏览器可执行文件路径
key = Registry.ClreplacedesRoot.OpenSubKey(@"http\shell\open\command\");
if (key != null)
{
string s = key.GetValue("").ToString();
//s就是你的默认浏览器,不过后面带了参数,把它截去,不过需要注意的是:不同的浏览器后面的参数不一样!
//"D:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"
var lastIndex = s.IndexOf(".exe", StringComparison.Ordinal);
if (lastIndex == -1)
{
lastIndex = s.IndexOf(".EXE", StringComparison.Ordinal);
}
var path = s.Substring(1, lastIndex + 3);
var result = Process.Start(path, url);
if (result == null)
{
// 方法2
// 调用系统默认的浏览器
var result1 = Process.Start("explorer.exe", url);
if (result1 == null)
{
// 方法3
Process.Start(url);
}
}
}
else
{
// 方法2
// 调用系统默认的浏览器
var result1 = Process.Start("explorer.exe", url);
if (result1 == null)
{
// 方法3
Process.Start(url);
}
}
return true;
}
catch (Exception error)
{
MessageBox.Show("无法使用默认浏览器:\n" + error.Message);
return false;
}
finally
{
key?.Dispose();
}
}
19
Source : Browser.cs
with MIT License
from charleszhang97
with MIT License
from charleszhang97
public bool OpenChrome(string url)
{
RegistryKey appPath = null;
try
{
// 64位注册表路径
var openKey = @"SOFTWARE\Wow6432Node\Google\Chrome";
if (IntPtr.Size == 4)
{
// 32位注册表路径
openKey = @"SOFTWARE\Google\Chrome";
}
appPath = Registry.LocalMachine.OpenSubKey(openKey);
// 谷歌卸载了,注册表还没有清空,程序会返回一个"系统找不到指定的文件。"的bug
if (appPath != null)
{
//MessageBox.Show(ExePath("chrome.exe"));
string exePath = ExePath("chrome.exe");
var result = Process.Start(exePath, url);
if (result == null)
{
return false;
}
}
else
{
var result = Process.Start("chrome.exe", url);
if (result == null)
{
return false;
}
}
return true;
}
catch
{
return false;
}
finally
{
appPath?.Dispose();
}
}
19
Source : Browser.cs
with MIT License
from charleszhang97
with MIT License
from charleszhang97
public bool OpenFireFox(string url)
{
RegistryKey appPath = null;
try
{
// 64位注册表路径
var openKey = @"SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox";
if (IntPtr.Size == 4)
{
// 32位注册表路径
openKey = @"SOFTWARE\Mozilla\Mozilla Firefox";
}
appPath = Registry.LocalMachine.OpenSubKey(openKey);
if (appPath != null)
{
//MessageBox.Show(ExePath("firefox.exe"));
string exePath = ExePath("firefox.exe");
var result = Process.Start(exePath, url);
if (result == null)
{
return false;
}
}
else
{
var result = Process.Start("firefox.exe", url);
if (result == null)
{
return false;
}
}
return true;
}
catch
{
return false;
}
finally
{
appPath?.Dispose();
}
}
19
Source : Utils.cs
with MIT License
from chatop2020
with MIT License
from chatop2020
public static object GetRegistryValue(RegistryKey regRoot, string regPath, string valueName,
object defaultValue = null)
{
var value = defaultValue;
using (var regKey = regRoot.OpenSubKey(regPath))
{
if (regKey != null)
value = defaultValue != null
? regKey.GetValue(valueName, defaultValue)
: regKey.GetValue(valueName);
}
return value;
}
19
Source : RegistryHelper.cs
with Apache License 2.0
from Chem4Word
with Apache License 2.0
from Chem4Word
public static void SendSetupActions()
{
string module = $"{_product}.{_clreplaced}.{MethodBase.GetCurrentMethod().Name}()";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(Constants.Chem4WordSetupRegistryKey, true);
if (rk != null)
{
string[] names = rk.GetValueNames();
List<string> values = new List<string>();
foreach (var name in names)
{
string message = rk.GetValue(name).ToString();
string timestamp = name;
int bracket = timestamp.IndexOf("[", StringComparison.InvariantCulture);
if (bracket > 0)
{
timestamp = timestamp.Substring(0, bracket).Trim();
}
values.Add($"{timestamp} {message}");
rk.DeleteValue(name);
}
if (values.Any())
{
Globals.Chem4WordV3.Telemetry.Write(module, "Setup", string.Join(Environment.NewLine, values));
}
}
}
19
Source : RegistryHelper.cs
with Apache License 2.0
from Chem4Word
with Apache License 2.0
from Chem4Word
public static void SendUpdateActions()
{
string module = $"{_product}.{_clreplaced}.{MethodBase.GetCurrentMethod().Name}()";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(Constants.Chem4WordUpdateRegistryKey, true);
if (rk != null)
{
string[] names = rk.GetValueNames();
List<string> values = new List<string>();
foreach (var name in names)
{
string message = rk.GetValue(name).ToString();
string timestamp = name;
int bracket = timestamp.IndexOf("[", StringComparison.InvariantCulture);
if (bracket > 0)
{
timestamp = timestamp.Substring(0, bracket).Trim();
}
values.Add($"{timestamp} {message}");
rk.DeleteValue(name);
}
if (values.Any())
{
Globals.Chem4WordV3.Telemetry.Write(module, "Update", string.Join(Environment.NewLine, values));
}
}
}
19
Source : RegistryHelper.cs
with Apache License 2.0
from Chem4Word
with Apache License 2.0
from Chem4Word
public static void SendExceptions()
{
string module = $"{_product}.{_clreplaced}.{MethodBase.GetCurrentMethod().Name}()";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(Constants.Chem4WordExceptionsRegistryKey, true);
int messageSize = 0;
if (rk != null)
{
string[] names = rk.GetValueNames();
List<string> values = new List<string>();
foreach (var name in names)
{
string message = rk.GetValue(name).ToString();
string timestamp = name;
int bracket = timestamp.IndexOf("[", StringComparison.InvariantCulture);
if (bracket > 0)
{
timestamp = timestamp.Substring(0, bracket).Trim();
}
values.Add($"{timestamp} {message}");
messageSize += timestamp.Length + message.Length;
if (messageSize > 30000)
{
SendData(module, values);
values = new List<string>();
messageSize = 0;
}
rk.DeleteValue(name);
}
SendData(module, values);
}
}
19
Source : UpdateHelper.cs
with Apache License 2.0
from Chem4Word
with Apache License 2.0
from Chem4Word
public static void ReadSavedValues()
{
string module = $"{_product}.{_clreplaced}.{MethodBase.GetCurrentMethod().Name}()";
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Constants.Chem4WordRegistryKey);
if (key != null)
{
var names = key.GetValueNames();
if (names.Contains(Constants.RegistryValueNameLastCheck))
{
try
{
var lastChecked = key.GetValue(Constants.RegistryValueNameLastCheck).ToString();
if (!string.IsNullOrEmpty(lastChecked))
{
DateTime last = SafeDate.Parse(lastChecked);
Globals.Chem4WordV3.VersionLastChecked = last;
}
}
catch
{
Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30);
}
}
else
{
Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30);
}
if (names.Contains(Constants.RegistryValueNameLastCheck))
{
try
{
var behind = key.GetValue(Constants.RegistryValueNameVersionsBehind).ToString();
Globals.Chem4WordV3.VersionsBehind = string.IsNullOrEmpty(behind) ? 0 : int.Parse(behind);
}
catch
{
Globals.Chem4WordV3.VersionsBehind = 0;
}
}
else
{
Globals.Chem4WordV3.VersionsBehind = 0;
}
}
else
{
Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30);
Globals.Chem4WordV3.VersionsBehind = 0;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.Message);
Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.StackTrace);
if (ex.InnerException != null)
{
Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.Message);
Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.StackTrace);
}
}
}
19
Source : SystemHelper.cs
with Apache License 2.0
from Chem4Word
with Apache License 2.0
from Chem4Word
private void GetDotNetVersionFromRegistry()
{
// https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
// https://en.wikipedia.org/wiki/Windows_10_version_history
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(DotNetVersionKey))
{
if (ndpKey != null)
{
int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
// .Net 4.8
if (releaseKey >= 528372)
{
DotNetVersion = $".NET 4.8 (W10 2004) [{releaseKey}]";
return;
}
if (releaseKey >= 528049)
{
DotNetVersion = $".NET 4.8 [{releaseKey}]";
return;
}
if (releaseKey >= 528040)
{
DotNetVersion = $".NET 4.8 (W10 1903) [{releaseKey}]";
return;
}
// .Net 4.7.2
if (releaseKey >= 461814)
{
DotNetVersion = $".NET 4.7.2 [{releaseKey}]";
return;
}
if (releaseKey >= 461808)
{
DotNetVersion = $".NET 4.7.2 (W10 1803) [{releaseKey}]";
return;
}
// .Net 4.7.1
if (releaseKey >= 461310)
{
DotNetVersion = $".NET 4.7.1 [{releaseKey}]";
return;
}
if (releaseKey >= 461308)
{
DotNetVersion = $".NET 4.7.1 (W10 1710) [{releaseKey}]";
return;
}
// .Net 4.7
if (releaseKey >= 460805)
{
DotNetVersion = $".NET 4.7 [{releaseKey}]";
return;
}
if (releaseKey >= 460798)
{
DotNetVersion = $".NET 4.7 (W10 1703) [{releaseKey}]";
return;
}
// .Net 4.6.2
if (releaseKey >= 394806)
{
DotNetVersion = $".NET 4.6.2 [{releaseKey}]";
return;
}
if (releaseKey >= 394802)
{
DotNetVersion = $".NET 4.6.2 (W10 1607) [{releaseKey}]";
return;
}
// .Net 4.6.1
if (releaseKey >= 394271)
{
DotNetVersion = $".NET 4.6.1 [{releaseKey}]";
return;
}
if (releaseKey >= 394254)
{
DotNetVersion = $".NET 4.6.1 (W10 1511) [{releaseKey}]";
return;
}
// .Net 4.6
if (releaseKey >= 393297)
{
DotNetVersion = $".NET 4.6 [{releaseKey}]";
return;
}
if (releaseKey >= 393295)
{
DotNetVersion = $".NET 4.6 (W10 1507) [{releaseKey}]";
return;
}
// .Net 4.5.2
if (releaseKey >= 379893)
{
DotNetVersion = $".NET 4.5.2 [{releaseKey}]";
return;
}
// .Net 4.5.1
if (releaseKey >= 378758)
{
DotNetVersion = $".NET 4.5.1 [{releaseKey}]";
return;
}
if (releaseKey >= 378675)
{
DotNetVersion = $".NET 4.5.1 [{releaseKey}]";
return;
}
// .Net 4.5
if (releaseKey >= 378389)
{
DotNetVersion = $".NET 4.5 [{releaseKey}]";
return;
}
if (releaseKey < 378389)
{
DotNetVersion = $".Net Version Unknown [{releaseKey}]";
}
}
}
}
See More Examples