示例#1
0
文件: Config.cs 项目: WildGenie/Razor
 public static void DeleteRegValue( Microsoft.Win32.RegistryKey hkey, string vname )
 {
     using ( RegistryKey key = hkey.OpenSubKey( RazorRegPath, true ) )
     {
         key.DeleteValue( vname, false );
     }
 }
示例#2
0
 //[RegistryPermissionAttribute(SecurityAction.PermitOnly, Write = @"HKEY_CURRENT_USER\SOFTWARE\DBFConvert")]
 //[RegistryPermissionAttribute(SecurityAction.PermitOnly, Write = @"HKEY_LOCAL_MACHINE\SOFTWARE\DBFConvert")]
 private void ClearReg(Microsoft.Win32.RegistryKey localRegKey, Microsoft.Win32.RegistryKey userRegKey)
 {
     string[] subkeys = localRegKey.OpenSubKey(regPath,true).GetSubKeyNames();
     foreach (string key in subkeys)
     {
         localRegKey.DeleteSubKeyTree(key);
     }
     subkeys = userRegKey.OpenSubKey(regPath,true).GetSubKeyNames();
     foreach (string key in subkeys)
     {
         localRegKey.DeleteSubKeyTree(key);
     }
 }
示例#3
0
文件: Main.cs 项目: herculesjr/razor
        public static string GetRegString( Microsoft.Win32.RegistryKey hkey, string vname )
        {
            try
            {
                RegistryKey key = hkey.OpenSubKey( RazorRegPath ) ;
                if ( key == null )
                {
                    key = hkey.CreateSubKey( RazorRegPath );
                    if ( key == null )
                        return null;
                }

                string v = key.GetValue( vname ) as string;

                if ( v == null )
                    return null;
                return v.Trim();
            }
            catch
            {
                return null;
            }
        }
示例#4
0
                private static void CopyKeyRecursive(Microsoft.Win32.RegistryKey sourceKey, Microsoft.Win32.RegistryKey destKey)
                {
                        foreach (string ValueName in sourceKey.GetValueNames()) {
                                object Val = sourceKey.GetValue(ValueName);
                                destKey.SetValue(ValueName, Val, sourceKey.GetValueKind(ValueName));
                        }

                        foreach (string SubKeyName in sourceKey.GetSubKeyNames()) {
                                using (Microsoft.Win32.RegistryKey sourceSubKey = sourceKey.OpenSubKey(SubKeyName, false))
                                using (Microsoft.Win32.RegistryKey destSubKey = destKey.CreateSubKey(SubKeyName)) {
                                        CopyKeyRecursive(sourceSubKey, destSubKey);
                                }
                        }
                }
示例#5
0
 public static void RenameSubKey(Microsoft.Win32.RegistryKey parentKey, string subKeyName, string newSubKeyName)
 {
         using (Microsoft.Win32.RegistryKey Src = parentKey.OpenSubKey(subKeyName, false))
         using (Microsoft.Win32.RegistryKey Dest = parentKey.CreateSubKey(newSubKeyName)) {
                 CopyKeyRecursive(Src, Dest);
         }
         parentKey.DeleteSubKeyTree(subKeyName);
 }
示例#6
0
	private static string FindByDisplayName(Microsoft.Win32.RegistryKey parentKey, string name)
	{

		string[] nameList = parentKey.GetSubKeyNames();
		for (int i = 0; i < nameList.Length; i++)
		{
			Microsoft.Win32.RegistryKey regKey = parentKey.OpenSubKey(nameList[i]);
			try
			{
				
				if (regKey.GetValue("DisplayName").ToString() == name)
				{
					return regKey.GetValue("InstallLocation").ToString();
				}
				else{
					//Debug.Log(nameList[i] + ", " + regKey.Name + " : " + regKey.GetValue("InstallLocation").ToString());
				}
			}
			catch { 
				//Debug.LogError ("AAA");
			}
		}
		return "";
	}
示例#7
0
        /// <summary>
        /// Verify that a specific user has access rights to a specific Registry Key
        /// </summary>
        /// <param name="userName">Name of the user to check for</param>
        /// <param name="root">Root key for the registry key</param>
        /// <param name="subKey">Registry key to check for</param>
        /// <param name="rights">Expected access rights</param>
        public static void VerifyRegistryKeyPermission(string userName, Microsoft.Win32.RegistryKey root, string subKey, RegistryRights rights)
        {
            RegistryKey registryKey = root.OpenSubKey(subKey);
            RegistrySecurity registrySecurity = registryKey.GetAccessControl();
            AuthorizationRuleCollection accessRules = registrySecurity.GetAccessRules(true, true, typeof(NTAccount));

            foreach (RegistryAccessRule accessRule in accessRules)
            {
                if (userName.ToLowerInvariant().Equals(accessRule.IdentityReference.Value.ToLowerInvariant()))
                {
                    if ((accessRule.RegistryRights & rights) == rights)
                    {
                        return;
                    }
                }
            }

            Assert.True(false, string.Format("User '{0}' do not have the correct permessions to RegistryKey '{1}/{2}'.", userName, root.ToString(), subKey));
        }
示例#8
0
        /// <summary>
        /// Remove Permissions on a Registry key
        /// </summary>
        /// <param name="userName">the user name to remove permissions for</param>
        /// <param name="root">the root hive</param>
        /// <param name="subKey">the key</param>
        public static void RemoveRegistryKeyPermission(string userName, Microsoft.Win32.RegistryKey root, string subKey)
        {
            RegistryKey registryKey = root.OpenSubKey(subKey);
            RegistrySecurity registrySecurity = registryKey.GetAccessControl();
            AuthorizationRuleCollection accessRules = registrySecurity.GetAccessRules(true, true, typeof(NTAccount));

            foreach (RegistryAccessRule accessRule in accessRules)
            {
                if (userName.ToLowerInvariant().Equals(accessRule.IdentityReference.Value.ToLowerInvariant()))
                {
                    registrySecurity.RemoveAccessRule(accessRule);
                }
            }
        }
示例#9
0
        /* ----------------------------------------------------------------- */
        ///
        /// Load
        /// 
        /// <summary>
        /// ユーザ毎の設定情報をレジストリからロードします。
        /// </summary>
        /// 
        /// <remarks>
        /// LastCheckUpdate の項目のみ、保存場所が異なるので別途処理を行って
        /// います。
        /// </remarks>
        /// 
        /* ----------------------------------------------------------------- */
        public bool Load(Microsoft.Win32.RegistryKey root)
        {
            try
            {
                using (var subkey = root.OpenSubKey(_RegRoot, false))
                {
                    using (var child = subkey.OpenSubKey(_RegVersion, false))
                    {
                        var document = new CubePdf.Settings.Document();
                        document.Read(child);
                        Load(document);
                    }

                    var date = subkey.GetValue(_RegLastCheck, string.Empty) as string;
                    if (!string.IsNullOrEmpty(date)) _lastcheck = DateTime.Parse(date as string);
                }
                return true;
            }
            catch (Exception /* err */) { return false; }
        }
 public void GetVsPackages(Microsoft.Win32.RegistryKey hiveRoot, Microsoft.Win32.RegistryKey editorKey, string editorExt)
 {
     if ((extension == null) || (System.StringComparer.OrdinalIgnoreCase.Compare(editorExt, extension) == 0))
     {
         string s = editorKey.GetValue("Package") as string;
         if (!System.String.IsNullOrEmpty(s))
         {
             using (Microsoft.Win32.RegistryKey registryKey = hiveRoot.OpenSubKey("Packages\\" + s))
             {
                 if ((registryKey != null) && !editors.ContainsKey(registryKey.Name))
                     editors.Add(registryKey.Name, new VsPackageInfo(registryKey));
             }
         }
     }
 }
        private static void LoadExtensions(Microsoft.Win32.RegistryKey hiveRoot, Helper registry)
        {
            if (hiveRoot == null)
                return;

            using (Microsoft.Win32.RegistryKey registryKey = hiveRoot.OpenSubKey("Editors"))
            {
                if (registryKey == null)
                    return;

                string[] sArr = registryKey.GetSubKeyNames();
                foreach (string keyName in sArr)
                {
                    using (Microsoft.Win32.RegistryKey registrySubKey = registryKey.OpenSubKey(keyName))
                    {
                        if (registrySubKey == null)
                            continue;

                        using (Microsoft.Win32.RegistryKey registryKeyExtensions = registrySubKey.OpenSubKey("Extensions"))
                        {
                            if (registryKeyExtensions == null)
                                continue;
                            string[] sArrExt = registryKeyExtensions.GetValueNames();
                            foreach (string n in sArrExt)
                            {
                                char[] chArr = new char[] { '.', ' ' };
                                string result = n.Trim(chArr).ToUpperInvariant();

                                registry.GetVsPackages(hiveRoot, registrySubKey, result);


                            }
                        }
                    }
                }
            }
        }
        DoesSoftwareKeyExist(
            string path,
            Microsoft.Win32.RegistryKey registryArea,
            bool query32Bit)
        {
            if (!OSUtilities.IsWindowsHosting)
            {
                return false;
            }

            var exists = true;
            using (var key = registryArea.OpenSubKey(SoftwareKeyPath(path, query32Bit)))
            {
                if (null == key)
                {
                    exists = false;
                }
            }

            return exists;
        }
        OpenSoftwareKey(
            string path,
            Microsoft.Win32.RegistryKey registryArea,
            bool query32Bit)
        {
            if (!OSUtilities.IsWindowsHosting)
            {
                return null;
            }

            var keyPath = SoftwareKeyPath(path, query32Bit);
            var key = registryArea.OpenSubKey(keyPath);
            if (null == key)
            {
                Log.DebugMessage("Registry key '{0}' on {1} not found", keyPath, registryArea.Name);
            }
            return key;
        }