GetSubKeyNames() public méthode

public GetSubKeyNames ( ) : string[]
Résultat string[]
 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 static bool IsApplicationInKey(RegistryKey key, string applicationName)
 {
     return key.GetSubKeyNames()
         .Select(key.OpenSubKey)
         .Select(subkey => subkey.GetValue("DisplayName") as string)
         .Any(displayName => displayName != null && displayName.Contains(applicationName));
 }
 /// <summary>
 /// 获取注册表项的子节点,并将其添加到树形控件节点中
 /// </summary>
 /// <param name="nodes"></param>
 /// <param name="rootKey"></param>
 public void GetSubKey(TreeNodeCollection nodes, RegistryKey rootKey)
 {
     if (nodes.Count != 0) return;
     //获取项的子项名称列表
     string[] keyNames = rootKey.GetSubKeyNames();
     //遍历子项名称
     foreach (string keyName in keyNames)
     {
     try
     {
     //根据子项名称功能注册表项
     RegistryKey key = rootKey.OpenSubKey(keyName);
     //如果表项不存在,则继续遍历下一表项
     if (key == null) continue;
     //根据子项名称创建对应树形控件节点
     TreeNode TNRoot = new TreeNode(keyName);
     //将注册表项与树形控件节点绑定在一起
     TNRoot.Tag = key;
     //向树形控件中添加节点
     nodes.Add(TNRoot);
     }
     catch
     {
     //如果由于权限问题无法访问子项,则继续搜索下一子项
     continue;
     }
     }
 }
 public static string[] GetRegSubkeys(string hive, string path)
 {
     // returns an array of the subkeys names under the specified path in the specified hive (HKLM/HKCU/HKU)
     try
     {
         Microsoft.Win32.RegistryKey myKey = null;
         if (hive == "HKLM")
         {
             myKey = Registry.LocalMachine.OpenSubKey(path);
         }
         else if (hive == "HKU")
         {
             myKey = Registry.Users.OpenSubKey(path);
         }
         else
         {
             myKey = Registry.CurrentUser.OpenSubKey(path);
         }
         String[] subkeyNames = myKey.GetSubKeyNames();
         return(myKey.GetSubKeyNames());
     }
     catch
     {
         return(new string[0]);
     }
 }
Exemple #5
0
 public static string[] GetRegSubkeys(string hive, string path)
 {
     try
     {
         Microsoft.Win32.RegistryKey myKey = null;
         if (hive == "HKLM")
         {
             myKey = Registry.LocalMachine.OpenSubKey(path);
         }
         else if (hive == "HKU")
         {
             myKey = Registry.Users.OpenSubKey(path);
         }
         else
         {
             myKey = Registry.CurrentUser.OpenSubKey(path);
         }
         String[] subkeyNames = myKey.GetSubKeyNames();
         return(myKey.GetSubKeyNames());
     }
     catch
     {
         return(new string[0]);
     }
 }
Exemple #6
0
 public static string[] GetRegSubkeys(string hive, string path)
 {
     // returns an array of the subkeys names under the specified path in the specified hive (HKLM/HKCU/HKU)
     try
     {
         Microsoft.Win32.RegistryKey myKey = null;
         if (hive == "HKLM")
         {
             myKey = Registry.LocalMachine.OpenSubKey(path);
         }
         else if (hive == "HKU")
         {
             myKey = Registry.Users.OpenSubKey(path);
         }
         else
         {
             myKey = Registry.CurrentUser.OpenSubKey(path);
         }
         String[] subkeyNames = myKey.GetSubKeyNames();
         return(myKey.GetSubKeyNames());
     }
     catch (Exception)
     {
         PrintUtils.Debug(String.Format(@"Registry {0}\{1} was not found", hive, path));
         return(new string[0]);
     }
 }
        /// <summary>
        /// Upgrades from v11 (Beta 2) through to v11.
        /// </summary>
        static void UpgradeFrom_10_9_1(RegistryKey reg)
        {
            // v11 (beta 2) (10.9.1) and later need highlighting settings to be copied.
            foreach (var themeName in reg.GetSubKeyNames()) {
                using (var themeKey = reg.OpenSubKey(themeName, true)) {
                    if (themeKey == null) continue;

                    themeKey.SetValue("ExtendInwardsOnly", 1);
                    themeKey.DeleteValue("TopToBottom", throwOnMissingValue: false);

                    string highlightColor = null, highlightStyle = null;

                    using (var key = themeKey.OpenSubKey("Caret")) {
                        if (key != null) {
                            highlightColor = (string)key.GetValue("LineColor");
                            highlightStyle = (string)key.GetValue("LineStyle");
                        }
                    }
                    themeKey.DeleteSubKeyTree("Caret", throwOnMissingSubKey: false);

                    foreach (var keyName in themeKey.GetSubKeyNames()) {
                        using (var key = themeKey.OpenSubKey(keyName, true)) {
                            if (key == null) continue;

                            if (key.GetValue("HighlightColor") == null) {
                                key.SetValue("HighlightColor", highlightColor);
                            }
                            if (key.GetValue("HighlightStyle") == null) {
                                key.SetValue("HighlightStyle", highlightStyle);
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        // Find out if Creo is installed on this machine.
        //  The method we use is to look through the uninstall list in the registry,
        //    since it has been verified that Creo updates this registry when it is
        //    installed
        bool CREO_present()
        {
            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        try
                        {
                            string str = subkey.GetValue("DisplayName", "").ToString();

                            if (new string[] { "Creo Parametric", "PTC Creo Parametric" }.Any(name => str.StartsWith(name)))
                            {
                                return(true);
                            }
                        }
                        catch (Exception)
                        {
                            // exceptions are thrown on every app in the registry without a proper display name
                            // we just want to skip these
                        }
                    }
                }
            }
            this.Logger.WriteError("CREO Parametric was NOT found on this Machine");
            return(false);
        }
        void InstalledApplication()
        {
            string path = FolderFileUtil.GetFullFilePath(textBox1.Text.Trim()) + "-InstalledApplication.txt";

            if (!File.Exists(path))
            {
                FileInfo   txtFile = new FileInfo(path);
                FileStream fs      = txtFile.Create();
                fs.Close();
            }

            StreamWriter sw = File.AppendText(path);

            sw.WriteLine(DateTime.Now.ToString());

            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        string displayName    = subkey.GetValue("DisplayName")?.ToString() ?? "";
                        string displayVersion = subkey.GetValue("DisplayVersion")?.ToString() ?? "";
                        string installDate    = subkey.GetValue("InstallDate")?.ToString() ?? "";
                        sw.WriteLine(string.Format("{0},{1},{2}", displayName, displayVersion, installDate));
                    }
                }
            }
            sw.Flush();
            sw.Close();
        }
        public static IEnumerable <WalletInstallInfo> GetInfo(RegistryKey regKeyBase, string regKeyStr)
        {
            using (Microsoft.Win32.RegistryKey key = regKeyBase.OpenSubKey(regKeyStr)) {
                if (key != null)
                {
                    foreach (string subkey_name in key.GetSubKeyNames().Where(k => !string.IsNullOrEmpty(k)))
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name)) {
                            var dispName    = subkey.GetValue("DisplayName");
                            var dispVersion = subkey.GetValue("DisplayVersion");
                            var path        = subkey.GetValue("UninstallString");
                            if (dispName != null && dispName.ToString().ToUpper().StartsWith("EMERCOIN CORE"))
                            {
                                Version version = new Version(0, 0);
                                if (dispVersion != null)
                                {
                                    Version.TryParse(dispVersion.ToString(), out version);
                                }

                                var info = new WalletInstallInfo();
                                info.DisplayName = dispName.ToString();
                                info.Version     = version;
                                info.Folder      = path != null?Directory.GetParent(path.ToString()).FullName : string.Empty;

                                info.Bitness = dispName.ToString().ToUpper() == "Emercoin Core (64-bit)".ToUpper() ? BitnessEnum.x64 : BitnessEnum.x32;

                                yield return(info);
                            }
                        }
                    }
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// 查看注册表项是否存在
        /// </summary>
        /// <param name="value">路经</param>
        /// <param name="name">项名称</param>
        /// <returns>是否存在</returns>
        private bool SearchItemRegEdit(string path, string name)
        {
            string[] subkeyNames;

            Microsoft.Win32.RegistryKey hkml = Microsoft.Win32.Registry.LocalMachine;

            Microsoft.Win32.RegistryKey software = hkml.OpenSubKey(path);

            subkeyNames = software.GetSubKeyNames();

            //取得该项下所有子项的名称的序列,并传递给预定的数组中

            foreach (string keyName in subkeyNames)      //遍历整个数组
            {
                if (keyName.ToUpper() == name.ToUpper()) //判断子项的名称
                {
                    hkml.Close();
                    return(true);
                }
            }

            hkml.Close();

            return(false);
        }
        public void Init()
        {
            try
            {
                var browsers = key.GetSubKeyNames();

                if (browsers[0].ToLower().Contains("firefox"))
                {
                    driver = new FirefoxDriver();
                }
                else if (browsers[0].ToLower().Contains("chrome"))
                {
                    driver = new ChromeDriver();
                }
                else if (browsers[0].ToLower().Contains("ieexplorer"))
                {
                    driver = new InternetExplorerDriver();
                }
                else if (browsers[0].ToLower().Contains("edge"))
                {
                    driver = new EdgeDriver();
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
Exemple #13
0
        private static void GetSubKey(RegistryKey key)
        {
            foreach (string skName in key.GetSubKeyNames())
            {
                using (RegistryKey sk = key.OpenSubKey(skName))
                {
                    if (sk == null)
                    {
                        continue;
                    }
                    if (sk.SubKeyCount > 0)
                    {
                        GetSubKey(sk);

                    }
                    if (sk.ValueCount > 0)
                    {
                        foreach (var valueName in sk.GetValueNames())
                        {
                            //Console.WriteLine(valueName);
                        }
                    }
                }
            }
        }
Exemple #14
0
        private static List <RegistrationElementDataClass> getKeyElement(Microsoft.Win32.RegistryKey registrationElement, string subKeyName, int level, ref List <RegistrationElementDataClass> registrationData)
        {
            if (registrationElement.ValueCount > 0)
            {
                List <RegistrationElementDataClass> registrationValue = getValue(registrationElement, subKeyName, level);
                registrationData.AddRange(registrationValue);
            }

            if (registrationElement.SubKeyCount > 0)
            {
                int           subLevel = level + 1;
                List <string> names    = registrationElement.GetSubKeyNames().ToList();
                foreach (string name in names)
                {
                    Microsoft.Win32.RegistryKey registrationSubKey = registrationElement.OpenSubKey(name);
                    if (registrationElement.ValueCount > 0)
                    {
                        List <RegistrationElementDataClass> registrationValue = getValue(registrationSubKey, subKeyName, subLevel);
                        registrationData.AddRange(registrationValue);
                    }
                    if (registrationSubKey.SubKeyCount > 0)
                    {
                        List <string> subKeyNames = registrationSubKey.GetSubKeyNames().ToList();
                        int           subSubLevel = subLevel + 1;
                        foreach (string subsubKeyName in subKeyNames)
                        {
                            getKeyElement(registrationSubKey.OpenSubKey(subsubKeyName), subKeyName, subSubLevel, ref registrationData);
                        } //END foreach (string subKeyName in subKeyNames)
                    }
                }         //END foreach(string name in names)
            }
            return(registrationData);
        }
        public void PrintFileTypes( RegistryKey root )
        {
            if( root == null ) return;
            string[] subkeys = root.GetSubKeyNames();
            foreach( string subname in subkeys )
            {
                // For each key, if it starts with . then it's a file type.
                // Otherwise, ignore it.
                if( subname == null ) continue;
                if( !subname.StartsWith(".") ) continue;

                // Open the key and find its default value.
                // If no default, skip this key, since it effectively
                // doesn't have an assigned type.
                RegistryKey subkey = root.OpenSubKey( subname );
                if( subkey == null ) continue;
                string typename = (string) subkey.GetValue( "" );
                if( typename == null ) continue; // No default value

                // If it has a value "Content Type", that's the mime type.
                string mimetype = null;
                mimetype = (string) subkey.GetValue( "Content Type" );

                // Find the descriptor type.
                RegistryKey typekey = root.OpenSubKey( typename );
                if( typekey == null ) continue;
                string displayName = (string) typekey.GetValue( "" );

                // Find the default icon.
                RegistryKey iconkey = typekey.OpenSubKey( "DefaultIcon" );
                if( iconkey == null ) continue;
                string iconname = (string) iconkey.GetValue( "" );

                // Split the icon descriptor to get the path and the resource ID.
                char[] separators = new char[1];
                separators[0] = ',';
                string[] iconparts = null;
                if( iconname != null )
                    iconparts = iconname.Split( separators );

                string iconfile = "";
                string iconres = "";
                if( iconparts != null && iconparts.Length <= 2 )
                {
                    iconfile = iconparts[0];
                    if( iconparts.Length == 2 ) iconres = iconparts[1];
                }

                Console.WriteLine( "Extension:      "+subname );
                Console.WriteLine( "  Type:         "+typename );
                Console.WriteLine( "  MimeType:     "+mimetype );
                Console.WriteLine( "  DisplayName:  "+displayName );
                Console.WriteLine( "  IconDesc:     "+iconname );

                // Needs checking.
                //Console.WriteLine( "  Icon:         "+iconfile );
                //Console.WriteLine( "  IconResource: "+iconres );
                Console.WriteLine( "" );
            }
        }
        //检测软件是否安装
        private static bool checkAPPInWindows(String app)
        {
            //定义注册表操作类并指向注册表的软件信息目录
            Microsoft.Win32.RegistryKey uninstallNode = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

            foreach (string subKeyName in uninstallNode.GetSubKeyNames())
            {
                Microsoft.Win32.RegistryKey subKey = uninstallNode.OpenSubKey(subKeyName); //定义注册表搜索子类
                object displayName = subKey.GetValue("DisplayName");                       //搜索键名为DisplayName的键————根据软件名字查找

                //针对特定软件,检查“InstallRoot”
                //RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\Kingsoft\Office\6.0\common\");  //查询wps——excel表格
                //string filewps = akeytwo.GetValue("InstallRoot").ToString();
                //if (File.Exists(filewps + @"\office6\et.exe"))

                if (displayName != null)
                {
                    if (displayName.ToString().Contains(app))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        private static string compNameFromReg()
        {
            string keyPath     = null;
            String registryKey = @"Volatile Environment";

            RegistryKey tempKey = null;

            using (Microsoft.Win32.RegistryKey key = Registry.CurrentUser.OpenSubKey(registryKey))
            {
                foreach (string subKeyName in key.GetSubKeyNames())
                {
                    using (tempKey = key.OpenSubKey(subKeyName))
                    {
                        keyPath = tempKey.Name.Remove(0, 18);
                    }
                }
            }

            //RegistryKey regedit = Registry.CurrentUser.OpenSubKey("Volatile Environment\\1", true);
            RegistryKey regedit = Registry.CurrentUser.OpenSubKey(keyPath, true);
            string      currentLoggedUserName = regedit.GetValue("CLIENTNAME").ToString();

            if (currentLoggedUserName == "")
            {
                //Console.WriteLine("No user name!");
                return("N/A");
            }
            else
            {
                return(currentLoggedUserName + " " + DateTime.Now);
            }
        }
Exemple #18
0
        static IEnumerable<RegistryKey> GetSubKeys(RegistryKey keyParentArg)
        {
            var keysFound = new List<RegistryKey>();

            try
            {
                if (keyParentArg.SubKeyCount > 0)
                {
                    foreach (var subKeyName in keyParentArg.GetSubKeyNames())
                    {
                        var keyChild = keyParentArg.OpenSubKey(subKeyName);
                        if (keyChild != null)
                        {
                            keysFound.Add(keyChild);
                        }

                        var keyGrandChildren = GetSubKeys(keyChild);

                        if (keyGrandChildren != null)
                        {
                            keysFound.AddRange(keyGrandChildren);
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.GetBaseException());
                throw;
            }
            return keysFound;
        }
Exemple #19
0
 /// <summary>
 /// 获取指定键值下存在某个值的子键
 /// </summary>
 /// <param name="regParentText">父键值路径</param>
 /// <param name="valName">值名称</param>
 /// <param name="val">值</param>
 /// <param name="regRoot">根键值。默认为LocalMachine</param>
 /// <returns></returns>
 private String GetRegPathByValue(string regParentText, string valName, string val, MSWin32.RegistryKey regRoot = null)
 {
     if (regRoot == null)
     {
         regRoot = MSWin32.Registry.LocalMachine;
     }
     using (MSWin32.RegistryKey reg = regRoot.OpenSubKey(regParentText))
     {
         if (reg != null)
         {
             string[] subKeyNames = reg.GetSubKeyNames();
             if (subKeyNames != null && subKeyNames.Length > 0)
             {
                 for (Int32 m = 0; m < subKeyNames.Length; m++)
                 {
                     string subKeyPath = regParentText + subKeyNames[m] + "\\";
                     if (IsRegValueExists(subKeyPath, valName, null))
                     {
                         string tmpVal = MSWin32.Registry.LocalMachine.OpenSubKey(subKeyPath).GetValue(valName)?.ToString();
                         if (tmpVal != null && tmpVal.Contains(val))
                         {
                             return(subKeyPath);
                         }
                     }
                 }
             }
         }
     }
     return(string.Empty);
 }
Exemple #20
0
        /// <summary>
        /// Recursively enumerates registry subkeys starting with strStartKey looking for
        /// "Device Parameters" subkey. If key is present, friendly port name is extracted.
        /// </summary>
        /// <param name="strStartKey">the start key from which to begin the enumeration</param>
        private string MineRegistryForJust4TrionicPortName(string strStartKey)
        {
            //            string strStartKey = "SYSTEM\\CurrentControlSet\\Enum";
            string[] oPortNamesToMatch = System.IO.Ports.SerialPort.GetPortNames();
            Microsoft.Win32.RegistryKey oCurrentKey = Registry.LocalMachine.OpenSubKey(strStartKey);
            string[] oSubKeyNames = oCurrentKey.GetSubKeyNames();

            object oFriendlyName   = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + strStartKey, "FriendlyName", null);
            string strFriendlyName = (oFriendlyName != null) ? oFriendlyName.ToString() : "N/A";

            if (strFriendlyName.StartsWith("mbed Serial Port"))
            {
                object oPortNameValue = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + strStartKey + "\\Device Parameters", "PortName", null);
                return(oPortNamesToMatch.Contains(oPortNameValue.ToString()) ? oPortNameValue.ToString() : null);
            }
            else
            {
                foreach (string strSubKey in oSubKeyNames)
                {
                    if (MineRegistryForJust4TrionicPortName(strStartKey + "\\" + strSubKey) != null)
                    {
                        return(MineRegistryForJust4TrionicPortName(strStartKey + "\\" + strSubKey));
                    }
                }
            }
            return(null);
        }
Exemple #21
0
 public static int[] WindowsRegQueryInfoKey(int hKey)
 {
     int[] result = new int[5] {
         -1, -1, -1, -1, -1
     };
     try
     {
         Microsoft.Win32.RegistryKey key = MapKey(hKey);
         result[0] = key.SubKeyCount;
         result[1] = 0;
         result[2] = key.ValueCount;
         foreach (string s in key.GetSubKeyNames())
         {
             result[3] = Math.Max(result[3], s.Length);
         }
         foreach (string s in key.GetValueNames())
         {
             result[4] = Math.Max(result[4], s.Length);
         }
     }
     catch (SecurityException)
     {
         result[1] = 5;
     }
     catch (UnauthorizedAccessException)
     {
         result[1] = 5;
     }
     return(result);
 }
Exemple #22
0
        public Slic3r()
        {
            InitializeComponent();
            if (Main.IsMono)
                panelCloseButtons.Location = new Point(panelCloseButtons.Location.X, panelCloseButtons.Location.Y - 14);
            comboFillPattern.SelectedIndex = 0;
            comboSolidFillPattern.SelectedIndex = 0;
            comboGCodeFlavor.SelectedIndex = 0;
            comboSupportMaterialTool.SelectedIndex = 0;
            comboSupportPattern.SelectedIndex = 0;
            comboSupportPattern.Text = "rectilinear";

            RegMemory.RestoreWindowPos("slic3rWindow", this);
            rconfigs = Main.main.repetierKey.CreateSubKey("slic3r");
            foreach (string s in rconfigs.GetSubKeyNames())
                comboConfig.Items.Add(s);
            config = (string)rconfigs.GetValue("currentConfig", "default");
            if (comboConfig.Items.Count == 0)
            {
                comboConfig.Items.Add("default");
                comboConfig.SelectedIndex = 0;
            }
            else
            {
                for (int i = 0; i < comboConfig.Items.Count; i++)
                {
                    if (comboConfig.Items[i].ToString() == config)
                    {
                        comboConfig.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
Exemple #23
0
        public void Register()
        {
            // Get the AutoCAD Applications key
            string sProdKey = HostApplicationServices.Current.UserRegistryProductRootKey;
            string sAppName = "AcadPalettes";

            Microsoft.Win32.RegistryKey regAcadProdKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sProdKey);
            Microsoft.Win32.RegistryKey regAcadAppKey  = regAcadProdKey.OpenSubKey("Applications", true);

            // Check to see if the "MyApp" key exists
            string[] subKeys = regAcadAppKey.GetSubKeyNames();
            foreach (string subKey in subKeys)
            {
                // If the application is already registered, exit
                if (subKey.Equals(sAppName))
                {
                    regAcadAppKey.Close();
                    return;
                }
            }

            // Get the location of this module
            string sAssemblyPath = Assembly.GetExecutingAssembly().Location;

            // Register the application
            Microsoft.Win32.RegistryKey regAppAddInKey = regAcadAppKey.CreateSubKey(sAppName);
            regAppAddInKey.SetValue("DESCRIPTION", sAppName, RegistryValueKind.String);
            regAppAddInKey.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord);
            regAppAddInKey.SetValue("LOADER", sAssemblyPath, RegistryValueKind.String);
            regAppAddInKey.SetValue("MANAGED", 1, RegistryValueKind.DWord);

            regAcadAppKey.Close();
        }
 //注册
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "")//判断公司名称是否为空
     {
         MessageBox.Show("公司名称不能为空");
         return;
     }
     if (textBox2.Text == "")//判断用户名称是否为空
     {
         MessageBox.Show("用户名称不能为空");
         return;
     }
     if (textBox3.Text == "")//判断注册码是否为空
     {
         MessageBox.Show("注册码不能为空");
         return;
     }
     //创建RegistryKey对象
     Microsoft.Win32.RegistryKey retkey1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("WXK").CreateSubKey("WXK.INI");
     foreach (string strName in retkey1.GetSubKeyNames()) //判断注册码是否过期
     {
         if (strName == textBox3.Text)                    //如果注册表中已经存在
         {
             MessageBox.Show("此注册码已经过期");
             return;
         }
     }
     //在注册表中创建子项
     Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("WXK").CreateSubKey("WXK.INI").CreateSubKey(textBox3.Text.TrimEnd());
     retkey.SetValue("UserName", textBox2.Text); //向注册表中写入公司名称
     retkey.SetValue("capataz", textBox1.Text);  //向注册表中写入用户名称
     retkey.SetValue("Code", textBox3.Text);     //向注册表中写入注册码
     MessageBox.Show("注册成功,您可以使用本软件");
 }
Exemple #25
0
        public static bool ExisteAPPInstalado(out string caminho)
        {
            bool isAPPInstalled = false;

            caminho = string.Empty;

            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        try
                        {
                            string displayName = (subkey.GetValue("DisplayName")).ToString();
                            if (displayName.Equals(NOME_APP_APP))
                            {
                                isAPPInstalled = true;
                                caminho        = subkey.GetValue("InstallLocation").ToString();
                                break;
                            }
                        }
                        catch
                        { }
                    }
                }
            }

            return(isAPPInstalled);
        }
Exemple #26
0
        public static List <string> ListInstalledPrograms()
        {
            List <string> res          = new List <string>();
            string        registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        if (subkey.ValueCount > 0)
                        {
                            var value = subkey.GetValue("DisplayName");
                            if (value != null)
                            {
                                res.Add(value.ToString());
                            }
                        }
                    }
                }
            }

            return(res);
        }
Exemple #27
0
        private void listInstalledPrograms()
        {
            string FTR_display_name = "For The Record";
            string FTR_publisher    = "ForTheRecord";
            string display_name     = "";
            string publisher        = "";
            string stmp             = "";
            string registry_key     = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    try
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                        {
                            display_name = subkey.GetValue("DisplayName").ToString();
                            publisher    = subkey.GetValue("Publisher").ToString();
                            if ((display_name.Contains(FTR_display_name) == true) &&
                                (publisher == FTR_publisher))
                            {
                                stmp = stmp + display_name + " installed version: " + subkey.GetValue("DisplayVersion") + "\n";
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //stmp = stmp + ex.ToString();
                    }
                }
            }
            MessageBox.Show(stmp);
        }
        public static int ObtenerVersiónInstalada()
        {
            int v = 0;

            try
            {
                string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
                {
                    foreach (string subkey_name in key.GetSubKeyNames())
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                        {
                            string str = subkey.GetValue("DisplayName").ToString();
                            if (str.Length >= 6 & string.Equals(str.Substring(0, 6), "ISMP v"))
                            {
                                string a = str.Remove(0, 13);

                                v = Convert.ToInt32(a.Replace(".", ""));
                                break;
                            }
                        }
                    }
                }
                return(v);
            }
            catch (Exception)
            {
                return(0);
            }
        }
        private void ImportRecursive(RegKeyEntry parent, RegistryKey key, RegKeyEntry relativeKey)
        {
            foreach (var name in key.GetSubKeyNames())
            {
                string keyName = name.ToLower();
                if (relativeKey.Keys.ContainsKey(keyName))
                {
                    RegKeyEntry entry = new RegKeyEntry(parent, name);
                    parent.Keys[name.ToLower()] = entry;
                    try
                    {
                        using (RegistryKey subkey = key.OpenSubKey(name))
                        {
                            ImportRecursive(entry, subkey, relativeKey.Keys[keyName]);
                        }
                    }
                    catch (System.Security.SecurityException)
                    {
                        // ignore
                    }
                }
            }

            foreach (var name in key.GetValueNames())
            {
                parent.Values[name.ToLower()] = new RegValueEntry(key, name);
            }
        }
Exemple #30
0
 public static void SetRegistryData(RegistryKey key, string path, string item, string value)
 {
     string[] keys = path.Split(new char[] {'/'},StringSplitOptions.RemoveEmptyEntries);
     try
     {
         if (keys.Count() == 0)
         {
             key.SetValue(item, value);
             key.Close();
         }
         else
         {
             string[] subKeys = key.GetSubKeyNames();
             if (subKeys.Where(s => s.ToLowerInvariant() == keys[0].ToLowerInvariant()).FirstOrDefault() != null)
             {
                 //Open subkey
                 RegistryKey sub = key.OpenSubKey(keys[0], (keys.Count() == 1));
                 if (keys.Length > 1)
                     SetRegistryData(sub, path.Substring(keys[0].Length + 1), item, value);
                 else
                     SetRegistryData(sub, string.Empty, item, value);
             }
             else
             {
                 SetRegistryData(key.CreateSubKey(keys[0]), path.Substring(keys[0].Length + 1), item, value);
             }
         }
     }
     catch { }
 }
Exemple #31
0
        private void LoadInstalledApplications()
        {
            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        try
                        {
                            ApplicationData data = new ApplicationData()
                            {
                                developer       = subkey.GetValue("Publisher").ToString(),
                                developerRating = "-9001",
                                displayName     = subkey.GetValue("DisplayName").ToString(),

                                shortDescription = subkey.GetValue("Publisher").ToString(),
                                fullDescription  = "Notepad on steroids with styling.",

                                importance        = Importance.LOW,
                                performanceImpact = PerformanceImpact.LOW
                            };

                            AddApplication(data);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
        }
Exemple #32
0
        //Accesses the uninstall list of windows and checks if it contains the pokerroom-name
        private static bool checkIfPokerRoomIsInstalled(string pokerRoom)
        {
            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        try
                        {
                            string name = (string)subkey.GetValue("DisplayName");
                            if (name.Contains(pokerRoom))
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(false);
        }
Exemple #33
0
        public static string GetProductInfo(String strKey, int optionalMIVersion = 0)
        {
            //Returns the value that belongs to the given keyname

            string registryKey = @"SOFTWARE\MapInfo\MapInfo\Professional";

            using (Microsoft.Win32.RegistryKey prokey = Registry.LocalMachine.OpenSubKey(registryKey))
            {
                string result = "";

                var versions = from a in prokey.GetSubKeyNames()
                               let r                       = prokey.OpenSubKey(a)
                                                  let name = r.Name
                                                             let slashindex = name.LastIndexOf(@"\")
                                                                              select new
                {
                    MapinfoVersion = Convert.ToInt32(name.Substring(slashindex + 1, name.Length - slashindex - 1))
                };
                foreach (var item in versions)
                {
                    if (optionalMIVersion == 0 || optionalMIVersion == item.MapinfoVersion)
                    {
                        string registryResultKey            = registryKey + "\\" + Convert.ToString(item.MapinfoVersion);
                        Microsoft.Win32.RegistryKey provkey = Registry.LocalMachine.OpenSubKey(registryResultKey);
                        result = provkey.GetValue(strKey).ToString();
                    }
                }
                return(result);
            }
        }
        CurApp ListProg()
        {
            string registry_key = String.Empty;

            registry_key = x86AppOnX64Os?
                           @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall":
                           @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            if (string.IsNullOrEmpty(registry_key) || string.IsNullOrEmpty(this.Name))
            {
                Console.WriteLine("reg path or appName is null");
                Environment.Exit(0);
            }

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name)) {
                        if (subkey.GetValue("DisplayName") != null && subkey.GetValue("DisplayName").ToString().Contains(Name))
                        {
                            string displayName     = subkey.GetValue("DisplayName").ToString();
                            string displayVersion  = (subkey.GetValue("DisplayVersion") != null) ? subkey.GetValue("DisplayVersion").ToString() : "";
                            string uninstallString = (subkey.GetValue("UninstallString") != null) ? subkey.GetValue("UninstallString").ToString() : "";
                            string installLocation = (subkey.GetValue("InstallLocation") != null) ? subkey.GetValue("InstallLocation").ToString() : "";

                            return(new CurApp(displayName, displayVersion, installLocation, uninstallString));
                        }
                    }
                }
            }

            return(null);
        }
Exemple #35
0
 //注册
 private void button2_Click(object sender, EventArgs e)
 {
     if (label5.Text == "")//判断是否生成注册码
     {
         MessageBox.Show("请生成注册码");
     }                             //如果没有生成则弹出提示
     else
     {
         string strNameKey = textBox1.Text.TrimEnd() + textBox2.Text.TrimEnd() + textBox3.Text.TrimEnd() + textBox4.Text.TrimEnd();                   //获取输入的注册码
         string strNumber  = label5.Text.Substring(0, 4) + label5.Text.Substring(5, 4) + label5.Text.Substring(10, 4) + label5.Text.Substring(15, 4); //获取生成的注册码
         if (strNameKey == strNumber)                                                                                                                 //判断输入的和生成的注册码是否相等
         {
             //打开相应的键值
             Microsoft.Win32.RegistryKey retkey1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI");
             foreach (string strName in retkey1.GetSubKeyNames())//判断注册码是否过期
             {
                 //如果输入的与注册表中原始的序列号相等则说明注册码过期
                 if (strName == strNameKey)
                 {
                     MessageBox.Show("此注册码已经过期");//弹出提示
                     return;
                 }
             }//开始注册信息
             Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI").CreateSubKey(strNumber.TrimEnd());
             retkey.SetValue("UserName", "明日科技");//设置注册名
             MessageBox.Show("注册成功!", "提示");//弹出提示
         }
         else//否则
         {
             MessageBox.Show("注册码输入错误");
         }                              //弹出错误提示
     }
 }
Exemple #36
0
        /// <summary>
        /// //Listet alle Instanzen (Unterschlüssel des aktuellen Schlüsseln) auf
        /// </summary>
        /// <returns>Gibt eine Liste mit gefundenen Instanznamen zurück</returns>
        public List <String> getInstances()
        {//Listet alle Instanzen auf
            List <String> myreturn = new List <string>();

            try
            {
                Microsoft.Win32.RegistryKey keyName = this.rootkey.OpenSubKey(this._subkey);
                String[] Subkeys = keyName.GetSubKeyNames();

                if (Subkeys.Length > 0) //Wenn mindestens ein Eintrag gefunden wurde
                {
                    foreach (String subkeyName in Subkeys)
                    {
                        //Console.WriteLine(keyName.OpenSubKey(subkeyName).GetValue("DisplayName"));
                        myreturn.Add(subkeyName.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                if (this.GeneralError != null)
                {
                    this.GeneralError(this, new ErrorEventArgs("Fehler beim Lesen der Instanzen. " + ex.ToString() + " " + ex.StackTrace));
                }
            }
            return(myreturn);
        }
Exemple #37
0
        public static List <String> GetSystemDSNList()
        {
            // generowanie listy DSN ################################################
            List <string> names = new List <string>();

            // get system dsn's

            Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.CurrentUser).OpenSubKey("Software");

            if (reg != null)
            {
                reg = reg.OpenSubKey("ODBC");
                if (reg != null)
                {
                    reg = reg.OpenSubKey("ODBC.INI");
                    if (reg != null)
                    {
                        // Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
                        foreach (string sName in reg.GetSubKeyNames())
                        {
                            names.Add(sName);
                        }
                    }
                    try
                    {
                        reg.Close();
                    }
                    catch { /* ignore this exception if we couldn't close */ }
                }
            }


            return(names);
        }
Exemple #38
0
        private void GetInstalledApplications()
        {
            string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                var listOfApplications = "";
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        if ((string)subkey.GetValue("DisplayName") != null && (string)subkey.GetValue("InstallLocation") != null)
                        {
                            installedApplications.Add(
                                new ApplicationObject {
                                ApplicationName = (string)subkey.GetValue("DisplayName"), ApplicationPath = (string)subkey.GetValue("InstallLocation")
                            });

                            listOfApplications += (string)subkey.GetValue("DisplayName") + " (" + (string)subkey.GetValue("InstallLocation") + ")" + Environment.NewLine;
                        }
                    }
                }

                richTextBox1.Text = listOfApplications;
            }
        }
Exemple #39
0
        public static void GetGOGApps()
        {
            string GOGFilepath;

            string GOGRegistry_key = @"SOFTWARE\WOW6432Node\GOG.com\GalaxyClient\paths";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(GOGRegistry_key))
            {
                GOGFilepath = key.GetValue("client").ToString() + "\\GalaxyClient.exe";
            }

            Exe gogExe = new Exe();

            gogExe.gameName = "GOG Galaxy";
            gogExe.filePath = GOGFilepath;
            Exes.Add(gogExe);

            string registry_key = @"SOFTWARE\WOW6432Node\GOG.com\Games";

            using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        Exe exe = new Exe();
                        exe.gameName = subkey.GetValue("GAMENAME").ToString();
                        exe.filePath = subkey.GetValue("LAUNCHCOMMAND").ToString();
                        exe.launcher = "GOG Galaxy";
                        Exes.Add(exe);
                    }
                }
            }
        }
Exemple #40
0
        protected RegistryKey FindSubKey(RegistryKey parent, string name)
        {
            RegistryKey key = parent.OpenSubKey(name);
            if (key != null) return key;

            name = name.ToUpper();

            List<RegistryKey> levelList = new List<RegistryKey>(100);

            string[] subKeys = parent.GetSubKeyNames();
            if (subKeys == null || subKeys.Length == 0)
            {
                return null;
            }
            foreach (string sub in subKeys)
            {
                RegistryKey k = null;
                try
                {
                    k = parent.OpenSubKey(sub);
                }
                catch (System.Security.SecurityException) { continue; }

                if (k == null) continue;
                levelList.Add(k);

                if (k.Name.ToUpper() == name)
                {
                    return k;
                }
            }
            //广度优先
            while (true)
            {
                if (levelList == null || levelList.Count == 0) break;

                List<RegistryKey> list = new List<RegistryKey>(levelList.Count);
                foreach (RegistryKey k in levelList)
                {
                    string[] subs = k.GetSubKeyNames();
                    foreach (string s in subs)
                    {
                        RegistryKey sk = null;
                        try
                        {
                            sk = k.OpenSubKey(s);
                        }
                        catch (System.Security.SecurityException) { continue; }

                        if (sk == null) continue;
                        if (s.ToUpper() == name) return sk;
                        list.Add(sk);
                    }
                }
                levelList = list;
            }

            return null;
        }
 public OwnerWindow_GuiTests()
 {
     RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"software", true /*writable*/);
     RegistryUtilities.CopyKey(rk, RegistryUtilities.RegistryBackupKeyName, RegistryUtilities.RegistryKeyName);
     CiderMainKey = rk.OpenSubKey(RegistryUtilities.RegistryKeyName, true);
     string ciderVersion = CiderMainKey.GetSubKeyNames()[0];
     CiderVersionKey = CiderMainKey.OpenSubKey(ciderVersion, true);
 }
 static void PrintRegKeys(RegistryKey rk)
 {
     string[] names = rk.GetSubKeyNames();
     Console.WriteLine("Subparts {0}:" , rk.Name);
     Console.WriteLine("------------------------------");
     foreach (string s in names)
         Console.WriteLine(s);
     Console.WriteLine("------------------------------");
 }
        public List <InstalledAppDetails> ReadVersions(string MachineName)
        {
            Logger.logEvent(LogLevel.INFO, "Entered ReadVersions");
            List <InstalledAppDetails> lstApplications = new List <Models.InstalledAppDetails>();

            try
            {
                HashSet <string> MachineNameSet = new HashSet <string>();
                string[]         _machineName   = MachineName.Split(',');
                foreach (string machine in _machineName)
                {
                    if (MachineNameSet.Contains(machine.ToLower()) || string.IsNullOrEmpty(machine))
                    {
                        continue;
                    }
                    else
                    {
                        MachineNameSet.Add(machine.ToLower());
                    }
                    //Retrieve the list of installed programs for each extrapolated machine name
                    var registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                    using (Microsoft.Win32.RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machine).OpenSubKey(registry_key))
                    {
                        foreach (string subkey_name in key.GetSubKeyNames())
                        {
                            using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                            {
                                try
                                {
                                    if (subkey.GetValue("DisplayName") != null && subkey.GetValue("Publisher").ToString().ToLower().Contains("aristocrat"))
                                    {
                                        lstApplications.Add(
                                            new InstalledAppDetails
                                        {
                                            MachineName        = machine,
                                            ApplicationName    = subkey.GetValue("DisplayName").ToString(),
                                            ApplicationVersion = subkey.GetValue("DisplayVersion").ToString(),
                                            InstalledDate      = DateTime.ParseExact(subkey.GetValue("InstallDate")?.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture).ToShortDateString(),
                                            Publisher          = subkey.GetValue("Publisher").ToString()
                                        });
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.logEvent(LogLevel.ERROR, "Error Reading Application Details --> " + ex.Message);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.logEvent(LogLevel.ERROR, "Outer Exception --> " + ex.Message);
            }
            return(lstApplications);
        }
        public static string[] getSubKeys(RegistryKey registryKey)
        {
            string[] subKeys = {};

            if (registryKey != null)
            {
                subKeys = registryKey.GetSubKeyNames();
            }

            return subKeys;
        }
        private void RegisterInterpreters(HashSet<string> registeredPaths, RegistryKey python, ProcessorArchitecture? arch) {
            foreach (var key in python.GetSubKeyNames()) {
                Version version;
                if (Version.TryParse(key, out version)) {
                    if (version.Major == 2 && version.Minor <= 4) {
                        // 2.4 and below not supported.
                        continue;
                    }

                    var installPath = python.OpenSubKey(key + "\\InstallPath");
                    if (installPath != null) {
                        var basePathObj = installPath.GetValue("");
                        if (basePathObj == null) {
                            // http://pytools.codeplex.com/discussions/301384
                            // messed up install, we don't know where it lives, we can't use it.
                            continue;
                        }
                        string basePath = basePathObj.ToString();
                        if (basePath.IndexOfAny(Path.GetInvalidPathChars()) != -1) {
                            // Invalid path in registry
                            continue;
                        }
                        if (!registeredPaths.Add(basePath)) {
                            // registered in both HCKU and HKLM
                            continue;
                        }

                        var actualArch = arch;
                        if (!actualArch.HasValue) {
                            actualArch = NativeMethods.GetBinaryType(Path.Combine(basePath, "python.exe"));
                        }

                        var id = _cpyInterpreterGuid;
                        var description = "Python";
                        if (actualArch == ProcessorArchitecture.Amd64) {
                            id = _cpy64InterpreterGuid;
                            description = "Python 64-bit";
                        }

                        _interpreters.Add(
                            new CPythonInterpreterFactory(
                                version,
                                id,
                                description,
                                Path.Combine(basePath, "python.exe"),
                                Path.Combine(basePath, "pythonw.exe"),
                                "PYTHONPATH",
                                actualArch ?? ProcessorArchitecture.None
                            )
                        );
                    }
                }
            }
        }
 void writeRegKeys(StreamWriter writer, int rootKeyLen, RegistryKey key)
 {
   writeRegKeyValues(writer, rootKeyLen, key);
   string[] subkeys = key.GetSubKeyNames();
   for (int t = 0; t < subkeys.Length; t++)
   {
     RegistryKey subkey = key.OpenSubKey(subkeys[t]);
     String keyName = subkey.Name.Substring(rootKeyLen);
     writeRegKeys(writer, rootKeyLen, subkey);
     subkey.Close();
   }
 }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks if a registry key exists.
		/// </summary>
		/// <param name="key">The base registry key of the key to check</param>
		/// <param name="subKey">The key to check</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static bool KeyExists(RegistryKey key, string subKey)
		{
			if (key == null)
				throw new ArgumentNullException("key");

			foreach (string s in key.GetSubKeyNames())
			{
				if (String.Compare(s, subKey, true) == 0)
					return true;
			}

			return false;
		}
        public System.Collections.ArrayList Get(String appVendor)
        {
            System.Collections.ArrayList alAppNameVer = new System.Collections.ArrayList();

            try {
                uninstallKey =
                    remoteLocalMachines.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
                subUninstallKeyNames = uninstallKey.GetSubKeyNames();
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                throw (e);
            }
            foreach (String subUninstallKey in subUninstallKeyNames) {

                try {
                    RegistryKey rk = uninstallKey.OpenSubKey(subUninstallKey);

                    String displayName = (String)rk.GetValue("DisplayName");
                    Object displayVersion = rk.GetValue("DisplayVersion");
                    if (displayName != null) {
                        if (displayName.Contains(appVendor)) {
                            AppNameVer anv = new AppNameVer();
                            anv.DisplayName = displayName;
                            if (displayName.Contains("Update") || displayName.Contains("Hotfix"))
                            {
                                anv.update = true;
                                String[] split = displayName.Split(new char[] { ' ' });
                                String patch = split.Last<String>();
                                anv.DisplayVersion = patch;
                            }
                            else
                            {
                                anv.update = false;
                                if(displayVersion != null )
                                    anv.DisplayVersion = displayVersion.ToString();
                            }
                            alAppNameVer.Add(anv);
                        }
                    }
                    rk.Close();
                }
                catch (Exception ex) {
                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine(ex.StackTrace);
                }
            }

            return alAppNameVer;
        }
Exemple #49
0
 private void validateKey(RegistryKey key)
 {
     String[] names = key.GetSubKeyNames();
     bool found = false;
     foreach (String s in names)
     {
         if (s == "Software\\Microsoft\\Office\\Excel\\Addins\\ReelImporter\\CurrentFolder")
             found = true;
     }
     if (!found)
     {
         key.CreateSubKey("Software\\Microsoft\\Office\\Excel\\Addins\\ReelImporter\\CurrentFolder", RegistryKeyPermissionCheck.ReadWriteSubTree);
     }
 }
Exemple #50
0
        private IEnumerable<MSBuildInfo> EnumerateVersions(RegistryKey versionListKey)
        {
            foreach (var versionName in versionListKey.GetSubKeyNames())
            {
                using (var versionKey = versionListKey.OpenSubKey(versionName))
                {
                    var msbuildHome = (string)versionKey.GetValue("MSBuildToolsPath");
                    var msbuildExe = Path.Combine(msbuildHome, "MSBuild.exe");

                    if (_fileSystem.FileExists(msbuildExe))
                        yield return new MSBuildInfo(new Version(versionName), msbuildExe);
                }
            }
        }
Exemple #51
0
		// Prints information about a given registry key
		public static String RegKeyToString(RegistryKey regKey)
		{
			if (regKey == null)
				return "";

			IList subKeys = regKey.GetSubKeyNames();
			StringBuilder outStr = new StringBuilder();

			SingleRegKey(outStr, regKey, 0);

			foreach (String subKeyName in subKeys)
				SingleRegKey(outStr, regKey.OpenSubKey(subKeyName), 2);
			return outStr.ToString();
		}
Exemple #52
0
 public void initializeSettings()
 {
     try
     {
         if (Registry.CurrentUser != null)
         {
             this.m_keyCurrentUser = Registry.CurrentUser;
             String[] subKeys = m_keyCurrentUser.GetSubKeyNames();
             bool found = false;
             foreach (String key in subKeys)
             {
                 if (key == "Software\\SHFL\\Applications\\ReleaseManager")
                     found = true;
             }
             if (found)
             {
                 m_keySettings = m_keyCurrentUser.OpenSubKey("Software\\SHFL\\Applications\\ReleaseManager");
             }
             else
             {
                 m_keySettings = m_keyCurrentUser.CreateSubKey("Software\\SHFL\\Applications\\ReleaseManager", RegistryKeyPermissionCheck.ReadWriteSubTree);
             }
         }
     }
     catch (Exception rException)
     {
         System.Windows.Forms.MessageBox.Show("Error code:\n" + rException.Message.ToString(), "Error Accessing Registry", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
     }
     if (m_keySettings.GetValue("TempFolder") != null)
     {
         tbTempPath.Text = m_keySettings.GetValue("TempFolder").ToString();
         m_strTempPath = tbTempPath.Text;
     }
     if (m_keySettings.GetValue("SVNUserName") != null)
     {
         tbSVNUserName.Text = m_keySettings.GetValue("SVNUserName").ToString();
         m_strSvnUser = tbSVNUserName.Text;
     }
     if (m_keySettings.GetValue("SVNPassword") != null)
     {
         tbSVNPassword.Text = m_keySettings.GetValue("SVNPassword").ToString();
         m_strSvnPassword = tbSVNPassword.Text;
     }
     if (m_keySettings.GetValue("SVNAutoLogin") != null)
     {
         cbSVNAutoLogin.Checked = Convert.ToBoolean(m_keySettings.GetValue("SVNAutoLogin").ToString());
         m_boolSVNAutoLogin = cbSVNAutoLogin.Checked;
     }
 }
 public FormPrinterSettings()
 {
     InitializeComponent();
     repetierKey = Registry.CurrentUser.CreateSubKey("Software\\Repetier");
     printerKey = repetierKey.CreateSubKey("printer");
     con = Main.conn;
     conToForm();
     comboPrinter.Items.Clear();
     foreach (string s in printerKey.GetSubKeyNames())
         comboPrinter.Items.Add(s);
     con.printerName = (string)repetierKey.GetValue("currentPrinter", "default");
     load(con.printerName);
     formToCon();
     UpdateDimensions();
 }
        private static List<FavoriteConfigurationElement> ImportFavoritesFromSubKeys(RegistryKey favoritesKey)
        {
            var registryFavorites = new List<FavoriteConfigurationElement>();
            foreach (string favoriteKeyName in favoritesKey.GetSubKeyNames())
            {
                using (RegistryKey favoriteKey = favoritesKey.OpenSubKey(favoriteKeyName))
                {
                    if (favoriteKey == null)
                        continue;

                    registryFavorites.Add(ImportRdpKey(favoriteKey, favoriteKeyName));
                }
            }

            return registryFavorites;
        }
 public FormPrinterSettings()
 {
     InitializeComponent();
     RegMemory.RestoreWindowPos("printerSettingsWindow", this);
     repetierKey = Custom.BaseKey; // Registry.CurrentUser.CreateSubKey("SOFTWARE\\Repetier");
     printerKey = repetierKey.CreateSubKey("printer");
     con = Main.conn;
     conToForm();
     comboPrinter.Items.Clear();
     foreach (string s in printerKey.GetSubKeyNames())
         comboPrinter.Items.Add(s);
     con.printerName = (string)repetierKey.GetValue("currentPrinter", "default");
     load(con.printerName);
     formToCon();
     UpdateDimensions();
     if (Custom.GetBool("simpleConnectionsConfig", false))
     {
         comboParity.Visible = false;
         comboStopbits.Visible = false;
         labelStopbits.Visible = false;
         labelParity.Visible = false;
     }
     if (Custom.GetBool("noDisposeArea", false))
     {
         labelDumpAreaDepth.Visible = false;
         labelDumpAreaFront.Visible = false;
         labelDumpAreaLeft.Visible = false;
         labelDumpAreaWidth.Visible = false;
         labelDumpUnit1.Visible = false;
         labelDumpUnit2.Visible = false;
         labelDumpUnit3.Visible = false;
         labelDumpUnit4.Visible = false;
         checkHasDumpArea.Visible = false;
         textDumpAreaDepth.Visible = false;
         textDumpAreaFront.Visible = false;
         textDumpAreaLeft.Visible = false;
         textDumpAreaWidth.Visible = false;
     }
     if (Custom.GetBool("noMaxHoming", false))
     {
         checkHomeXMax.Visible = false;
         checkHomeYMax.Visible = false;
         checkHomeZMax.Visible = false;
     }
     Main.main.languageChanged += translate;
     translate();
 }
Exemple #56
0
        private void ParseSoundKeys(RegistryKey rk)
        {
            foreach (string strSubKey in rk.GetSubKeyNames())
            {

                // Ignores ".Default" Subkey
                if ((strSubKey.CompareTo(".Current") == 0) || (strSubKey.CompareTo(".Modified") == 0))
                {
                    // Gets the (default) key and sees if the file exists
                    RegistryKey rk2 = rk.OpenSubKey(strSubKey);

                    if (rk2 != null)
                    {
                        ProgressWorker.I.EnQ(string.Format("Scanning {0}\\{1}", rk2.ToString(), string.Empty));

                        string strSoundPath = rk2.GetValue("") as string;

                        if (!string.IsNullOrEmpty(strSoundPath))
                        {
                            if (!File.Exists(strSoundPath))
                            {
                                this.BadKeys.Add(new InvalidKeys()
                                {
                                    Root = Registry.LocalMachine,
                                    Subkey = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
                                    Key = string.Empty,
                                    Name = "(default)"
                                });
                            }
                        }
                    }

                }
                else if (!string.IsNullOrEmpty(strSubKey))
                {
                    RegistryKey rk2 = rk.OpenSubKey(strSubKey);
                    if (rk2 != null)
                    {
                        ParseSoundKeys(rk2);
                    }
                }

            }

            return;
        }
        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;
            }
        }
Exemple #58
0
		private static void LoadGenerators(RegistryKey generatorsKey)
		{
			if (generatorsKey == null)
			{
				return;
			}
			string[] generatorNames = generatorsKey.GetSubKeyNames();
			for (int i = 0; i < generatorNames.Length; i++)
			{
				string generatorName = generatorNames[i];
				RegistryKey generatorKey = null;
				try
				{
					generatorKey = generatorsKey.OpenSubKey(generatorName, RegistryKeyPermissionCheck.ReadSubTree);
					string type = generatorKey.GetValue("Type", null) as string;
					IORMGenerator ormGenerator = null;
					if (String.Equals(type, "XSLT", StringComparison.OrdinalIgnoreCase))
					{
						ormGenerator = new XslORMGenerator(generatorKey);
					}
					else if (String.Equals(type, "Class", StringComparison.OrdinalIgnoreCase))
					{
						ormGenerator = LoadGeneratorClass(generatorKey);
					}

					if (ormGenerator != null)
					{
						System.Diagnostics.Debug.Assert(String.Equals(generatorName, ormGenerator.OfficialName, StringComparison.OrdinalIgnoreCase));
						//ormGenerator.ORMCustomTool = this;
						ORMGenerators.Add(ormGenerator.OfficialName, ormGenerator);
					}
				}
				catch (Exception ex)
				{
					// TODO: Localize message.
					ReportError("WARNING: Exception ocurred while trying to load generator \"" + generatorName + "\" in ORMCustomTool:", ex);
				}
				finally
				{
					if (generatorKey != null)
					{
						generatorKey.Close();
					}
				}
			}
		}
Exemple #59
0
        protected object FindRegValue(RegistryKey key, string name)
        {
            if (key == null) return null;
            object value = key.GetValue(name);
            if (value != null) return value;

            string[] subKeys = key.GetSubKeyNames();
            if (subKeys == null || subKeys.Length == 0) return null;

            foreach (string sk in subKeys)
            {
                var k = key.OpenSubKey(sk);
                object o = FindRegValue(k, name);
                if (o != null)
                {
                    return o;
                }
            }
            return null;
        }
        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);
            }
        }