public void CopyFromRegistry(RegistryKey keyToSave) { if (keyToSave == null) { throw new ArgumentNullException("keyToSave"); } this.ValueNames = keyToSave.GetValueNames(); if (this.ValueNames == null) { this.ValueNames = new string[0]; } this.Values = new object[this.ValueNames.Length]; for (int i = 0; i < this.ValueNames.Length; i++) { this.Values[i] = keyToSave.GetValue(this.ValueNames[i]); } this.KeyNames = keyToSave.GetSubKeyNames(); if (this.KeyNames == null) { this.KeyNames = new string[0]; } this.Keys = new SerializableRegistryKey[this.KeyNames.Length]; for (int j = 0; j < this.KeyNames.Length; j++) { this.Keys[j] = new SerializableRegistryKey(keyToSave.OpenSubKey(this.KeyNames[j])); } }
private void registryTraveller(RegistryKey look_here) { if (worker.CancellationPending) return; foreach (string check_me in look_here.GetValueNames()) { RegistryKeyValue value = new RegistryKeyValue(); try { value.key = look_here.Name; value.value = check_me; if (look_here.GetValue(check_me) != null) { value.data = look_here.GetValue(check_me).ToString(); if (value.data.Length >= path.FullDirPath.Length && path.FullDirPath.ToLower() == value.data.Substring(0, path.FullDirPath.Length).ToLower()) { outputLine(Environment.NewLine + "Key:" + value.key); outputLine("Value: " + value.value); output("Data: "); outputPath(value.data); } } } catch { } } try { RegistryKey sub_key; foreach (string check_me in look_here.GetSubKeyNames()) { try { sub_key = look_here.OpenSubKey(check_me); if (sub_key != null) registryTraveller(sub_key); } catch (System.Security.SecurityException) { } } } catch { } }
public static string[] GetExtInfo(string extension) { string keyval=""; string[] retInfo = new string[2]; using (sysreg = Registry.ClassesRoot.OpenSubKey(extension)) { string[] keys = sysreg.GetValueNames(); foreach (string key in keys) { if (key == null || key == "") { keyval = (string)sysreg.GetValue(key, ""); break; } } } if (keyval == null || keyval == "") { retInfo[1] = (extension.Remove(0, 1)).ToUpper() + " File"; retInfo[0] = "Other"; } else if (keyval.Contains(',')) { retInfo[0] = keyval; retInfo[1] = (extension.Remove(0, 1)).ToUpper() + " File"; } else { using (sysreg = Registry.ClassesRoot.OpenSubKey(keyval)) { string[] keys = sysreg.GetValueNames(); foreach (string key in keys) { if (key == null || key == "") { retInfo[1] = (string)sysreg.GetValue(key); break; } } } using(sysreg = Registry.ClassesRoot.OpenSubKey(keyval + "\\DefaultIcon")) { string[] keys = sysreg.GetValueNames(); foreach (string key in keys) { if (key == null || key == "") { retInfo[0] = (string)sysreg.GetValue(key); break; } } } } return retInfo; }
public static List <String> GetSystemDriverList() { List <string> names = new List <string>(); // get system dsn's Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.LocalMachine).OpenSubKey("Software"); if (reg != null) { reg = reg.OpenSubKey("ODBC"); if (reg != null) { reg = reg.OpenSubKey("ODBCINST.INI"); if (reg != null) { reg = reg.OpenSubKey("ODBC Drivers"); if (reg != null) { // Get all DSN entries defined in DSN_LOC_IN_REGISTRY. foreach (string sName in reg.GetValueNames()) { names.Add(sName); } } try { reg.Close(); } catch { /* ignore this exception if we couldn't close */ } } } } return(names); }
/// <summary> /// 查看注册表的值是否存在 /// </summary> /// <param name="value">路经</param> /// <param name="value">查看的值</param> /// <returns>是否成功</returns> private bool SearchValueRegEdit(string path, string value) { string[] subkeyNames; Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path); subkeyNames = software.GetValueNames(); //取得该项下所有键值的名称的序列,并传递给预定的数组中 foreach (string keyName in subkeyNames) { if (keyName.ToUpper() == value.ToUpper()) //判断键值的名称 { hkml.Close(); return(true); } } hkml.Close(); return(false); }
private void button2_Click(object sender, EventArgs e) { try { //清除内容 listBox1.Items.Clear(); NumAdd = 0; //定义注册表顶级结点 命名空间Microsoft.Win32 Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\TypedPaths", true); //判断键是否存在 if (key != null) { //检索包含此项关联的所有值名称 即url1 url2 url3 string[] names = key.GetValueNames(); foreach (string str in names) { //获取url中相关联的值 listBox1.Items.Add(key.GetValue(str).ToString()); NumAdd++; } //显示获取文件总数 this.textBox1.Text = NumAdd + "个文件"; } /* 注册表的使用操作 * //创建键 * //在HKEY_CURRENT_USER下创建Eastmount键 * RegistryKey test1 = Registry.CurrentUser.CreateSubKey("Eastmount"); * //创建键结构 HKEY_CURRENT_USER\Software\Eastmount\test2 * RegistryKey test2 = Registry.CurrentUser.CreateSubKey(@"Software\Eastmount\test2"); * * //删除HKEY_CURRENT_USER下创建Eastmount键 * Registry.CurrentUser.DeleteSubKey("Eastmount"); * //删除创建的子键test2 * Registry.CurrentUser.DeleteSubKeyTree(@"Software\Eastmount"); * * //获取Environment中路径 * string strPath; * strPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Environment", * "path", "Return this default if path does not exist"); * MessageBox.Show(strPath); * * //设置键值Version=1.25 * Registry.SetValue(@"HKEY_CURRENT_USER\Software\YourSoftware", "Version", "1.25"); * //设置键值 * Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths", "url4", @"E:\dota"); * * //隐藏桌面我的电脑 * RegistryKey rgK = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"); * rgK.SetValue("{20D04FE0-3AEA-1069-A2D8-08002B30309D}",0); */ } catch (Exception msg) //异常处理 { MessageBox.Show(msg.Message); } }
public RegistryKeyItem(RegistryKey hiveKey, string displayName) { this.hiveKey = hiveKey; this.displayName = displayName; lazyChildKeys = new Lazy<List<RegistryKeyItem>>(CreateChildKeys); lazyAttributes = new Lazy<List<KeyAttribute>>(() => hiveKey.GetValueNames().Select(valueName => new KeyAttribute(valueName, hiveKey.GetValue(valueName).ToString())).ToList()); }
public AddFontForm() { InitializeComponent(); fontsKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts"); foreach (string font in fontsKey.GetValueNames()) if (font.EndsWith("(TrueType)")) comboBoxFonts.Items.Add(font); fontFile = ""; }
/// <summary> /// Gets all the values from a given Microsoft.Win32.RegistryKey /// object as a System.Collections.Generic.Dictionary<string, object>, /// with the dictionary key being the value name, and the dictionary value being the /// registry value. /// </summary> /// <param name="rk">RegistryKey to retrieve values from.</param> public static Dictionary<string, object> GetValuesFromRegistryKey(RegistryKey rk) { Dictionary<string, object> dict = new Dictionary<string, object>(); string[] names = rk.GetValueNames(); foreach (string name in names) {; dict.Add(name, rk.GetValue(name)); } return dict; }
public static bool Check(RegistryKey runKey, string appName) { try { string[] runList = runKey.GetValueNames(); foreach (string item in runList) { if (item.Equals(appName)) return true; } return false; } catch (Exception ex) { EventLog.WriteEntry("BW", ex.Message, EventLogEntryType.Error); return false; } }
private static bool InnerCompare(RegistryKey A, RegistryKey B, string root,ref Dictionary<string, Data> output) { bool current = true; try { if (A != null) { // Process A foreach (var Name in A.GetValueNames()) { string EntryName = root + A.Name + "::" + Name; var dat = new Data(); dat.SetA(A.GetValue(Name), A.GetValueKind(Name)); output.Add(EntryName, dat); } foreach (var keyName in A.GetSubKeyNames()) { RegistryKey subA = A.OpenSubKey(keyName); RegistryKey subB = B == null ? null : B.OpenSubKey(keyName); current &= InnerCompare(subA, subB, root + keyName + @"\", ref output); } } if (B != null) { foreach (var Name in B.GetValueNames()) { string EntryName = root + B.Name + "::" + Name; Data dat = output.ContainsKey(EntryName) ? output[EntryName] : new Data(); dat.SetB(B.GetValue(Name), B.GetValueKind(Name)); output[EntryName] = dat; } foreach (var keyName in B.GetSubKeyNames()) { // when we get here, we have already cleared everything present in the A side RegistryKey subB = B.OpenSubKey(keyName); current &= InnerCompare(null, subB, root + keyName + @"\", ref output); } } return current; } catch (Exception e) { return false; } }
/// 搜索注册表指定项 /// <param name="key">注册表项</param> private void SearchRegistryKey(RegistryKey key) { if (key == null) return; //判断项是否为空 //获取注册表项的键名列表 string[] valueNames = key.GetValueNames(); //将注册表项加入到搜索状态提示中 SetSearchState(key.ToString()); //遍历所有键名,判断键名或键值中是否含有搜索的关键字 foreach (string valueName in valueNames) { //搜索的关键字 string keywords = tBKeywords.Text; //获取键值并转换成字符串类型 string value = key.GetValue(valueName).ToString(); //判断键名或键值中是否含有搜索的关键字 if (valueName.Contains(keywords) || value.Contains(keywords)) {//如果含有搜索关键字 //将该键在注册表中的全路径添加到搜索结果列表中 AddSearchState(key.ToString() + "\\" + valueName); } } //获取项的所有子项名 string[] subKeyNames = key.GetSubKeyNames(); //遍历所有子项,并对其进行搜索 foreach (string subKeyName in subKeyNames) { try { //根据子项名获取子项 RegistryKey subKey = key.OpenSubKey(subKeyName); //如果子项为空,则继续搜索下一子项 if (subKey == null) continue; //搜索子项 SearchRegistryKey(subKey); } catch (Exception) { //如果由于权限问题无法访问子项,则继续搜索下一子项 continue; } } key.Close(); }
// Used to get the basic info that is used by this type // of node protected override Object ProcessChild(RegistryKey key, String subKeyName) { BasicInfo info = new BasicInfo(key, subKeyName); foreach (String valueName in key.GetValueNames()) { if (valueName != null && !valueName.Equals("") && info.Name == null) info.Name = (String)key.GetValue(valueName); } if (info.Name == null) { info.Name = subKeyName; info.PrintName = subKeyName + " (guid)"; } info._infoType = "Category"; return info; }
public static Dictionary<string, string> listAllKeys(RegistryKey registryKey) { try { Dictionary<string, string> regKeyValues = new Dictionary<string, string>(); string[] keys = registryKey.GetValueNames(); foreach (string key in keys) { object value = registryKey.GetValue(key); regKeyValues.Add(key, value == null? null : value.ToString()); } return regKeyValues; } catch(Exception e) { throw new RegException(e); } }
private static void RecurseCopyKey(RegistryKey sourceKey, RegistryKey destinationKey) { //copy all the values foreach (string valueName in sourceKey.GetValueNames()) { object objValue = sourceKey.GetValue(valueName); RegistryValueKind valKind = sourceKey.GetValueKind(valueName); destinationKey.SetValue(valueName, objValue, valKind); } //For Each subKey //Create a new subKey in destinationKey //Call myself foreach (string sourceSubKeyName in sourceKey.GetSubKeyNames()) { RegistryKey sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName); RegistryKey destSubKey = destinationKey.CreateSubKey(sourceSubKeyName); RecurseCopyKey(sourceSubKey, destSubKey); } }
public frmServices2(frmServices.ServicesUIText uiText, RegistryKey key) { InitializeComponent(); this.serviceText = uiText; serviceRegKey = key; this.Text = uiText.ConfigText; this.labelServiceList.Text = uiText.MyServicesText; this.lblAddService.Text = uiText.AddServiceText; this.lblExample.Text = uiText.ExampleText; // Add all of the existing service hosts - lower case (case insensitive) string[] serviceHosts = serviceRegKey.GetValueNames(); currentServices = new ArrayList(); foreach (string host in serviceHosts) { string lowerHost = host.ToLower(); currentServices.Add(lowerHost); listBoxServices.Items.Add(lowerHost); } }
private void RecurseCopyKey(RegistryKey sourceKey, RegistryKey destinationKey) { //copy all the values foreach (string valueName in sourceKey.GetValueNames()) { object objValue = sourceKey.GetValue(valueName); RegistryValueKind valKind = sourceKey.GetValueKind(valueName); destinationKey.SetValue(valueName, objValue, valKind); } //For Each subKey //Create a new subKey in destinationKey //Call myself foreach (string sourceSubKeyName in sourceKey.GetSubKeyNames()) { RegistryKey sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl); RegistryKey destSubKey = destinationKey.CreateSubKey(sourceSubKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree); RecurseCopyKey(sourceSubKey, destSubKey); } }
public static Session getSession(RegistryKey registryKey) { var ret = new Session(); if (registryKey != null) { var valueKeys = registryKey.GetValueNames(); foreach (var key in valueKeys) { var value = new RegistryValue { kind = registryKey.GetValueKind(key), key = key, value = registryKey.GetValue(key).ToString() }; ret.Add(value); } } return ret; }
internal bool InstallChecker(string FileDIR,RegistryKey Reg) { bool isInstalled = true; //파일시스템에서 검색 if (!(Directory.GetFiles(FileDIR, "psql").Length > 0)) { isInstalled = false; } //레지스트리에서 검색 if (Reg.GetValueNames().Length ==0) { isInstalled = false; } // 설치된 경우는 true반환 if (isInstalled) { return true; } else { return false; } }
// VS CODE TODO: RegistryKey should be replaced with some sort of generic configuration store, and it should NOT be // optional. public ExceptionCategorySettings(ExceptionManager parent, /*OPTIONAL*/ RegistryKey categoryKey) { _parent = parent; if (categoryKey != null) { this.CategoryName = categoryKey.GetSubKeyNames().Single(); this.DefaultCategoryState = RegistryToExceptionBreakpointState(categoryKey.GetValue("*")); Dictionary<string, ExceptionBreakpointState> exceptionSettings = new Dictionary<string, ExceptionBreakpointState>(); foreach (string valueName in categoryKey.GetValueNames()) { if (string.IsNullOrEmpty(valueName) || valueName == "*" || !ExceptionManager.IsSupportedException(valueName)) continue; ExceptionBreakpointState value = RegistryToExceptionBreakpointState(categoryKey.GetValue(valueName)); if (value == this.DefaultCategoryState) { Debug.Fail("Redundant exception trigger found in the registry."); continue; } exceptionSettings.Add(valueName, value); } this.DefaultRules = new ReadOnlyDictionary<string, ExceptionBreakpointState>(exceptionSettings); } else { this.CategoryName = string.Empty; this.DefaultCategoryState = ExceptionBreakpointState.None; this.DefaultRules = new ReadOnlyDictionary<string, ExceptionBreakpointState>(new Dictionary<string, ExceptionBreakpointState>(0)); } this._settingsUpdate = new SettingsUpdates(this.DefaultCategoryState, this.DefaultRules); }
/// <summary> /// Static method that copies the contents of one key to another /// </summary> /// <param name="fromKey">The source key for the copy</param> /// <param name="toKey">The target key for the copy</param> public static void CopyKey( RegistryKey fromKey, RegistryKey toKey ) { foreach( string name in fromKey.GetValueNames() ) toKey.SetValue( name, fromKey.GetValue( name ) ); foreach( string name in fromKey.GetSubKeyNames() ) using( RegistryKey fromSubKey = fromKey.OpenSubKey( name ) ) using( RegistryKey toSubKey = toKey.CreateSubKey( name ) ) { CopyKey( fromSubKey, toSubKey ); } }
/// <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); key.DeleteSubKey( name ); } }
private static void DumpKey(RegistryKey key, int depth) { try { string indent = new string(' ', depth * 2); Trace.WriteLine(indent + key); // Enumerate values foreach (string valueName in key.GetValueNames()) { if (String.IsNullOrEmpty(valueName)) { Trace.WriteLine(indent + "Default Value: " + key.GetValue(valueName)); } else { Trace.WriteLine(indent + "Name: " + valueName + " --> Value: " + key.GetValue(valueName)); } } // Enumerate subkeys foreach (string subKeyName in key.GetSubKeyNames()) { using (RegistryKey subKey = key.OpenSubKey(subKeyName)) { DumpKey(subKey, depth + 1); } } } catch (Exception ex) { Trace.Fail("Exception thrown while dumping registry key: " + key + "\r\n" + ex); if (IsRegistryException(ex)) return; throw; } }
private static string GetRInstallPathFromRCoreKegKey(RegistryKey rCoreKey, StringBuilder logger) { string installPath = null; string[] subKeyNames = rCoreKey.GetSubKeyNames(); string[] valueNames = rCoreKey.GetValueNames(); if (valueNames.Length == 0) { doLogSetEnvVarWarn("Did not find any value names under " + rCoreKey, logger); return RecurseFirstSubkey(rCoreKey, logger); } else { const string installPathKey = "InstallPath"; if (valueNames.Contains(installPathKey)) { doLogSetEnvVarInfo("Found sub-key InstallPath under " + rCoreKey, logger); installPath = (string)rCoreKey.GetValue(installPathKey); } else { doLogSetEnvVarInfo("Did not find sub-key InstallPath under " + rCoreKey, logger); if (valueNames.Contains("Current Version")) { doLogSetEnvVarInfo("Found sub-key Current Version under " + rCoreKey, logger); string currentVersion = GetRCurrentVersionStringFromRegistry(rCoreKey); if (subKeyNames.Contains(currentVersion)) { var rVersionCoreKey = rCoreKey.OpenSubKey(currentVersion); return GetRInstallPathFromRCoreKegKey(rVersionCoreKey, logger); } else { doLogSetEnvVarWarn("Sub key "+ currentVersion + " not found in " + rCoreKey, logger); } } else { doLogSetEnvVarInfo("Did not find sub-key Current Version under " + rCoreKey, logger); return RecurseFirstSubkey(rCoreKey, logger); } } } doLogSetEnvVarInfo(string.Format("InstallPath value of key " + rCoreKey.ToString() + ": {0}", installPath == null ? "null" : installPath), logger); return installPath; }
public static List<RegValue> GetValues(RegistryKey key) { int valueCount = key.ValueCount; if (valueCount == 0) return new List<RegValue>(); List<RegValue> values = new List<RegValue>(valueCount); String[] valueNames = key.GetValueNames(); for (int i = 0; i < valueNames.Length; i++) values.Add(new RegValue(key, valueNames[i])); return values; }
public static TargetInfo ReadFromRegistry(CodeToolInfo tool, RegistryKey targetKey, string targetName) { string fileName = null; string kind = importAfter; string condition = ""; string versions = ""; Dictionary<string, string> properties = new Dictionary<string, string>(); foreach (string name in targetKey.GetValueNames()) { if (String.Compare(name, "TargetsFile", true) == 0) { fileName = targetKey.GetValue(name) as string; } else if (String.Compare(name, "TargetsKind", true) == 0) { kind = targetKey.GetValue(name) as string; } else if (String.Compare(name, "TargetsCondition", true) == 0) { condition = targetKey.GetValue(name) as string; } else if (String.Compare(name, "MSBuildVersions", true) == 0 || String.Compare(name, "MSBuildVersion", true) == 0) { versions = targetKey.GetValue(name) as string; } else if (name != null && name.Length > 0) { string val = targetKey.GetValue(name) as string; properties.Add(name, val); } } if (fileName == null) return null; return new TargetInfo(tool, targetName, fileName, kind, versions, condition, properties); }
private static void Find(RegistryKey key, string skFilter, string keyName) { if (key.Name.Contains(skFilter)) { foreach (string vn in key.GetValueNames()) { if (vn == keyName) { FindResult.Add(key); break; } } } foreach (string skn in key.GetSubKeyNames()) { try { Find(key.OpenSubKey(skn), skFilter, keyName); } catch { } } }
/// <summary> /// Returns an instance of <see cref="InsuranceRegistryKey"/> built from data read from the specified registry key. /// </summary> /// <exception cref="ArgumentException"> /// An <see cref="ArgumentException"/> is thrown if any of the values specified in the registrykey is invalid. /// =OR= /// An <see cref="ArgumentException"/> is thrown if the specified registrykey doesn't contain an "Installer" subkey. /// </exception> /// <param name="registryKey"></param> /// <returns></returns> public static InsuranceRegistryKey Read(RegistryKey registryKey) { var values = new List<string>(registryKey.GetValueNames()); if (values.Count < 2) throw new Exception(); var guidValue = registryKey.GetValue("guid"); var machineId = registryKey.GetValue("machineId"); var creationDatetimeValue = registryKey.GetValue("creationDateTime"); if (guidValue == null) throw new ArgumentException("The specified registry key doesn't contain a value for \"guid\"", "registryKey"); if (machineId == null) throw new ArgumentException("The specified registry key doesn't contain a value for \"machineId\"", "registryKey"); if (creationDatetimeValue == null) throw new ArgumentException("The specified registry key doesn't contain a value for \"creationDateTime\"", "registryKey"); // Construct the GUID Guid guid; try { guid = new Guid(guidValue.ToString()); } catch (Exception e) { throw new ArgumentException("The specified registry key contains a corrupt value for \"guid\"", "registryKey", e); } // Construct the DateTime DateTime creationDateTime; if (!DateTime.TryParse(creationDatetimeValue.ToString(), out creationDateTime)) throw new ArgumentException("The specified registry key contains a corrupt value for \"creationDateTime\"", "registryKey"); // Read the InstallerDescription InstallerDescription installer; using (var installerKey = registryKey.OpenSubKey("Installer")) { if (installerKey == null) throw new ArgumentException("The specified registry key doesn't contain a subkey for \"Installer\"", "registryKey"); installer = ReadInstallerDescription(installerKey); } // Read the insured assemblies var assemblies = new List<AssemblyName>(values.Count - 2); foreach (var value in values) if (value.StartsWith("assembly")) assemblies.Add(new AssemblyName(registryKey.GetValue(value).ToString())); return new InsuranceRegistryKey(registryKey.Name.Substring(Registry.CurrentUser.Name.Length), guid, installer, machineId.ToString(), creationDateTime, assemblies); }
void copyipv6address(RegistryKey source, uint luidindex, uint iftype, RegistryKey dest) { if (source == null) { Trace.WriteLine("No IPv6 Config found"); return; } //Construct a NET_LUID & convert to a hex string ulong prefixval = (((ulong)iftype) << 48) | (((ulong)luidindex) << 24); // Fix endianness to match registry entry & convert to string byte[] prefixbytes = BitConverter.GetBytes(prefixval); Array.Reverse(prefixbytes); string prefixstr = BitConverter.ToInt64(prefixbytes,0).ToString("x16"); Trace.WriteLine("Looking for prefix "+prefixstr); string[] keys = source.GetValueNames(); foreach (string key in keys) { Trace.WriteLine("Testing "+key); if (key.StartsWith(prefixstr)) { Trace.WriteLine("Found "+key); //Replace prefix with IPv6_Address____ before saving string newstring="IPv6_Address____"+key.Substring(16); Trace.WriteLine("Writing to " + dest.ToString()+" "+newstring); dest.SetValue(newstring, source.GetValue(key)); } } Trace.WriteLine("Copying addresses with prefix "+prefixstr+" done"); }
protected string GeneratePrinterPort(RegistryKey regkey) { int portnum = 0; Regex re = new Regex("^winspool,ne([0-9][0-9]):$"); foreach (string name in regkey.GetValueNames()) { string driver_port = regkey.GetValue(name, null) as string; Match match; if (driver_port != null && (match = re.Match(driver_port)).Success) { int curportnum = Convert.ToInt32(match.Groups[1].Value, 10); if (curportnum >= portnum) { portnum = curportnum + 1; } } } return String.Format("Ne{0:D2}:", portnum); }
private static RegistryValueKind GetValueKind( RegistryKey key, string keyName ) { RegistryValueKind valueKind = RegistryValueKind.Unknown; if ( key.GetValueNames().Contains( keyName ) ) { valueKind = key.GetValueKind( keyName ); } if ( valueKind == RegistryValueKind.Unknown ) { valueKind = RegistryValueKind.String; } return valueKind; }
private static bool CheckSqlServer(RegistryKey instanceKey) { return instanceKey.GetValueNames().Any(); }
/// //////////////////////////////////////////// /// //////////////////////////////////////////// /// //// IFEO Check ///////////////// /// //////////////////////////////////////////// /// //////////////////////////////////////////// public static void IFEO() { String registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" [+] Checking IFEO SubKeys"); var dnum = 0; var gnum = 0; // Store each IFEO subkey NAME in subkeyName foreach (String subkeyName in key.GetSubKeyNames()) { String ikey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + subkeyName; //Get the values of each subkey and store in vkey using (Microsoft.Win32.RegistryKey vkey = Registry.LocalMachine.OpenSubKey(ikey)) { Console.ForegroundColor = ConsoleColor.Cyan; //Look in each subkey value for 'debugger' and 'globalflag' foreach (var subVals in vkey.GetValueNames()) { if (subVals == "Debugger") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] 'Debugger' Value found in:"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + vkey); dnum = dnum + 1; } if (subVals == "GlobalFlag") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] 'GlobalFlag' Value found in:"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + vkey); gnum = gnum + 1; } } } } if (dnum == 0) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - 'Debugger' Value not found"); } if (gnum == 0) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - 'GlobalFlag' Value not found"); } } String registryKeyWOW = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"; using (Microsoft.Win32.RegistryKey keyWOW = Registry.LocalMachine.OpenSubKey(registryKeyWOW)) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" [+] Checking Wow6432Node IFEO SubKeys"); var dnumWOW = 0; var gnumWOW = 0; // Store each IFEO subkey NAME in subkeyName foreach (String subkeyNameWOW in keyWOW.GetSubKeyNames()) { String ikeyWOW = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + subkeyNameWOW; //Get the values of each subkey and store in vkey using (Microsoft.Win32.RegistryKey vkeyWOW = Registry.LocalMachine.OpenSubKey(ikeyWOW)) { Console.ForegroundColor = ConsoleColor.Cyan; //Look in each subkey value for 'debugger' and 'globalflag' foreach (var subValsWOW in vkeyWOW.GetValueNames()) { if (subValsWOW == "Debugger") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] 'Debugger' Value found in:"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + vkeyWOW); dnumWOW = dnumWOW + 1; } if (subValsWOW == "GlobalFlag") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] 'GlobalFlag' Value found in:"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + vkeyWOW); gnumWOW = gnumWOW + 1; } } } } if (dnumWOW == 0) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - Wow6432Node 'Debugger' Value not found"); } if (gnumWOW == 0) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - Wow6432Node 'GlobalFlag' Value not found"); } } String silentKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit"; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" [+] Checking for SilentProcessExit Key"); using (Microsoft.Win32.RegistryKey skey = Registry.LocalMachine.OpenSubKey(silentKey)) { if (skey == null) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - SilentProcessExit SubKey does not exist"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] SilentProcessExit SubKey Found!"); foreach (String skeyName in skey.GetSubKeyNames()) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + skey); } } } String silentKeyWOW = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\SilentProcessExit"; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" [+] Checking for Wow6432Node SilentProcessExit Key"); using (Microsoft.Win32.RegistryKey skeyWOW = Registry.LocalMachine.OpenSubKey(silentKeyWOW)) { if (skeyWOW == null) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(" [+] Success - Wow6432Node SilentProcessExit SubKey does not exist"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" [-] Wow6432Node SilentProcessExit SubKey Found!"); foreach (String skeyNameWOW in skeyWOW.GetSubKeyNames()) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(" " + skeyWOW); } } } }
void copyregkey(RegistryKey src, RegistryKey dest) { if (src != null) { RegistrySecurity srcac = src.GetAccessControl(); RegistrySecurity destac = new RegistrySecurity(); string descriptor = srcac.GetSecurityDescriptorSddlForm(AccessControlSections.Access); destac.SetSecurityDescriptorSddlForm(descriptor); dest.SetAccessControl(destac); string[] valuenames = src.GetValueNames(); foreach (string valuename in valuenames) { Trace.WriteLine("Copy " + src.Name + " " + valuename + " : " + dest.Name); dest.SetValue(valuename, src.GetValue(valuename)); } string[] subkeynames = src.GetSubKeyNames(); foreach (string subkeyname in subkeynames) { Trace.WriteLine("DeepCopy " + src.Name + " " + subkeyname + " : " + dest.Name); copyregkey(src.OpenSubKey(subkeyname), dest.CreateSubKey(subkeyname)); } } }
/// <summary> /// Liest alle in der Registry gespeicherten Sessions aus /// </summary> /// <returns>Treenode mit allen gefundenen Sessions</returns> public static TreeNode ImportSessionsFromRegistry() { TreeNode retVal = new TreeNode("PuTTY Sessions"); retVal.ImageIndex = -1; retVal.SelectedImageIndex = -1; try { Microsoft.Win32.RegistryKey f = default(Microsoft.Win32.RegistryKey); List <string> lst = new List <string>(); //Inhalt der Sessions List <string> lst_n = new List <string>(); //Namen der Sessions try { f = Registry.CurrentUser.OpenSubKey("Software\\SimonTatham\\PuTTY\\Sessions", false); foreach (string s in f.GetSubKeyNames()) { try { string session = ""; Microsoft.Win32.RegistryKey nf = default(Microsoft.Win32.RegistryKey); nf = Registry.CurrentUser.OpenSubKey("Software\\SimonTatham\\PuTTY\\Sessions\\" + s); lst_n.Add(s.Replace("%20", " ").Replace("%2F", "/")); foreach (string a in nf.GetValueNames()) { string o = Registry.GetValue("HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions\\" + s, a, null).ToString(); session = (a + "=" + o) + Environment.NewLine + session; } lst.Add(session); } catch (Exception ex) { } } } catch (Exception ex) { } for (int i = 0; i <= lst_n.Count - 1; i++) { if (lst_n[i].IndexOfAny(Path.GetInvalidFileNameChars()) != -1 || lst_n[i].Contains(" ")) { foreach (char c in Path.GetInvalidFileNameChars()) { lst_n[i] = lst_n[i].Replace(c.ToString(), "_"); } lst_n[i] = lst_n[i].Replace(" ", "_"); } string filepath = Path.Combine(ApplicationSettings.LocalRepositoryPath, lst_n[i].ToString()); if (File.Exists(filepath)) { File.Delete(filepath); } File.WriteAllText(filepath, lst[i].ToString()); TreeNode nN = new TreeNode(lst_n[i].ToString()); nN.ImageIndex = 6; nN.StateImageIndex = 6; nN.SelectedImageIndex = 6; retVal.Nodes.Add(nN); } } catch (Exception ex) { } return(retVal); }