상속: NativeObjectSecurity
예제 #1
0
		public static void SetAccessControl (this RegistryKey key, RegistrySecurity registrySecurity)
		{
			if (key == null)
				throw new ArgumentNullException (nameof (key));

			key.SetAccessControl (registrySecurity);
		}
예제 #2
0
        static bool WriteRegistry()
        {
            try
            {
                // 로컬호스트 관리자그룹을 사용해서 레지스트리 쓰기 권한을 할당한다.
                // 도메인에 속하는 컴퓨터인 경우 아래 코드가 잘 될지 안될지 모르겠다.
                RegistryAccessRule allow_write_rule = new RegistryAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), RegistryRights.FullControl, AccessControlType.Allow);
                RegistrySecurity securitySettings = new RegistrySecurity();
                securitySettings.AddAccessRule(allow_write_rule);

                // MSDN의 샘플은 HKEY_CLASSROOT 에 저장하게 되어있는데
                // HKEY_CURRENT_USER 에 저장하는걸 권장한다고 하더라.
                // 난 그냥 HKEY_LOCAL_MACHINE 에 저장한다.
                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes", RegistryKeyPermissionCheck.ReadWriteSubTree);
                key.SetAccessControl(securitySettings);

                // 스키마 생성
                RegistryKey reg_base = key.CreateSubKey("mytro.RecPlayer");
                if (null == reg_base)
                    return false;
                // 기본값 설정
                reg_base.SetValue("", "mytro record player URI", RegistryValueKind.String);
                // 이게 꼭 필요한지는 모르겠음
                reg_base.SetValue("Content Type", "application/x-mytrorec", RegistryValueKind.String);
                // 이게 있어야 브라우저에서 클릭했을때 동작한다.
                reg_base.SetValue("URL Protocol", "", RegistryValueKind.String);

                // icon 설정
                RegistryKey icon = reg_base.CreateSubKey("DefaultIcon");
                if (null == icon)
                    return false;
                icon.SetValue("", @"C:\MYTRO\RecordPlayer\MytroPlayer.exe,1", RegistryValueKind.String);

                // 핸들러 설정 (shell open 을 만들어준다.)
                RegistryKey shell = reg_base.CreateSubKey("shell");
                if (null == shell)
                    return false;
                shell.SetValue("", "open", RegistryValueKind.String);

                RegistryKey open = shell.CreateSubKey("open");
                if (null == open)
                    return false;

                RegistryKey command = open.CreateSubKey("command");
                if (null == command)
                    return false;

                // 실행파일도 Environment.SpecialFolder.ApplicationData 에 넣고 사용하는걸 권장하는데 왜 그런지는 잘 모르겠음...
                // 저 규칙에 따른다면 경로는 이렇게 된다. C:/Users/홍준기/AppData/Roaming/RecordPlayer/MytroPlayer.exe
                command.SetValue("", @"""C:\MYTRO\RecordPlayer\MytroPlayer.exe"" ""%1""", RegistryValueKind.String);

                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return false;
        }
예제 #3
0
        public static void SetAccessControl(this RegistryKey key, RegistrySecurity registrySecurity)
        {
            if (registrySecurity == null)
            {
                throw new ArgumentNullException(nameof(registrySecurity));
            }

            registrySecurity.Persist(key.Handle, key.Name);
        }
예제 #4
0
 private RegistryKey OpenExplorerPoliciesKey()
 {
     RegistrySecurity RegistrySecurity = new RegistrySecurity();
     WindowsIdentity WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
     RegistryAccessRule AccessRule = new RegistryAccessRule(WindowsIdentity.Name, RegistryRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
     RegistrySecurity.AddAccessRule(AccessRule);
     RegistrySecurity.SetAccessRuleProtection(false, true);
     RegistryKey RegistryKey = Registry.LocalMachine.OpenSubKey(ExplorerPolitiesRegistryPath, true);
     RegistryKey.SetAccessControl(RegistrySecurity);
     return RegistryKey;
 }
예제 #5
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            _prevIndex = Utilities.ToInt32LittleEndian(buffer, offset + 0x04);
            _nextIndex = Utilities.ToInt32LittleEndian(buffer, offset + 0x08);
            _usageCount = Utilities.ToInt32LittleEndian(buffer, offset + 0x0C);
            int secDescSize = Utilities.ToInt32LittleEndian(buffer, offset + 0x10);

            byte[] secDesc = new byte[secDescSize];
            Array.Copy(buffer, offset + 0x14, secDesc, 0, secDescSize);
            _secDesc = new RegistrySecurity();
            _secDesc.SetSecurityDescriptorBinaryForm(secDesc);

            return 0x14 + secDescSize;
        }
예제 #6
0
        public static void SalvarRegistro(string sSubKey, string sKey, string sValor)
        {
            string user = Environment.UserDomainName + "\\" + Environment.UserName;
            RegistrySecurity rs = new RegistrySecurity();
            rs.AddAccessRule(new RegistryAccessRule(user,
            RegistryRights.FullControl,
            InheritanceFlags.None,
            PropagationFlags.None,
            AccessControlType.Allow));

            RegistryKey rk = Registry.CurrentConfig.OpenSubKey("hlp", true);
            rk = rk.CreateSubKey(sSubKey, RegistryKeyPermissionCheck.Default, rs);
            rk.SetValue(sKey, sValor);

        }
예제 #7
0
        private static void Main(params string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(Resources.Help);
                Pause();
                return;
            }

            if (args.Contains(Factory.FormFlag))
            {
                CommandLineBuilder form = new CommandLineBuilder();
                form.ShowDialog();
                return;
            }

            Console.WriteLine(Resources.NotifyStartMessage);

            Factory factory = new Factory();
            ExecutionInfo executionInfo = factory.CreateExecutationInfo();
            // TODO: validate parameters

            try
            {
                RegistryKey registryKey = branchRegistryKey[executionInfo.MainBranch];

                registryKey = registryKey.OpenSubKey(executionInfo.PathToKey, true);

                RegistryAccessRule registryAccessRule = new RegistryAccessRule(
                    executionInfo.User,
                    executionInfo.Permission,
                    executionInfo.InheritanceFlags,
                    executionInfo.PropagationFlags,
                    executionInfo.AccessControlType);

                RegistrySecurity registrySecurity = new RegistrySecurity();
                registrySecurity.SetAccessRule(registryAccessRule);
                registryKey.SetAccessControl(registrySecurity);

                Console.WriteLine(Resources.SuccessMessage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.ToString());
            }

            Pause();
        }
        private static RegistryKey GetRegistryKey()
        {
            // Create a security context for a new key that we will use to store our data.
            // The security context will restrict access to only our user.
            string user = Environment.UserDomainName + "\\" + Environment.UserName;
            RegistrySecurity security = new RegistrySecurity();
            RegistryAccessRule rule = new RegistryAccessRule(user,
                    RegistryRights.FullControl,
                    InheritanceFlags.ContainerInherit,
                    PropagationFlags.None,
                    AccessControlType.Allow);
            security.AddAccessRule(rule);

            RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",
                RegistryKeyPermissionCheck.ReadWriteSubTree, security);

            return key;
        }
        private void writeRegistry(String authcode)
        {
            RegistrySecurity rs = new RegistrySecurity();

            // Allow the current user to read and delete the key.
            //
            string user = Environment.UserDomainName + "\\" + Environment.UserName;

            rs.AddAccessRule(new RegistryAccessRule(user,
            RegistryRights.ReadKey | RegistryRights.Delete,
            InheritanceFlags.None,
            PropagationFlags.None,
            AccessControlType.Allow));

            Registry.LocalMachine.CreateSubKey("SOFTWARE\\SimuTraining", RegistryKeyPermissionCheck.ReadWriteSubTree);

            RegistryKey SimuTraining = Registry.LocalMachine.CreateSubKey("SOFTWARE\\SimuTraining");
            SimuTraining.SetValue("authcode", authcode);
            SimuTraining.Close();
        }
예제 #10
0
 static RegistryUtilities()
 {
     MSec = new RegistrySecurity();
     string user = Environment.UserDomainName +
                   "\\" + Environment.UserName;
     try
     {
         RegistryAccessRule rule = new RegistryAccessRule(user,
                                           RegistryRights.ReadKey | RegistryRights.WriteKey
                                           | RegistryRights.Delete | RegistryRights.FullControl | RegistryRights.CreateSubKey,
                                           InheritanceFlags.ContainerInherit,
                                           PropagationFlags.None,
                                           AccessControlType.Allow
             );
         MSec.AddAccessRule(rule);
     }
     catch
     {
     }
 }
예제 #11
0
 public ForcedProxy()
 {
     InitializeComponent();
     RegistryKey key;
     key = Registry.LocalMachine.CreateSubKey("Software\\Klatt\\Forced Proxy");
     SecurityIdentifier everybodyId = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
     NTAccount everybody = everybodyId.Translate(typeof(NTAccount)) as NTAccount;
     RegistryAccessRule rule = new RegistryAccessRule(
         everybody.ToString(),
         RegistryRights.FullControl,
         InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
         PropagationFlags.None,
         AccessControlType.Allow);
     RegistrySecurity security = new RegistrySecurity();
     security.AddAccessRule(rule);
     key.SetAccessControl(security);
     ip.Text = (string)key.GetValue(null, "127.0.0.1");
     key.Close();
     programs.Items.Clear();
     readAvaiablePrograms();
     setInstallButtonCaption();
 }
예제 #12
0
 public unsafe RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck,  RegistryOptions registryOptions, RegistrySecurity registrySecurity) 
 {
     return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, registryOptions);
 }        
예제 #13
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public void SetAccessControl(RegistrySecurity registrySecurity) {
            EnsureWriteable();
            if (registrySecurity == null)
                throw new ArgumentNullException("registrySecurity");

            registrySecurity.Persist(hkey, keyName);
        }
예제 #14
0
        private void SetupIRCDDE()
        {
            //check if we have elevated (admin level)
            if (GetOperatingSystemName().IndexOf("Windows") > -1 && CheckElevated() == true)
            {
                Microsoft.Win32.RegistryKey rKey = null;
                try
                {
                    rKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("irc", true);
                    if (rKey != null)
                    {
                        Microsoft.Win32.RegistryKey sKey = rKey.OpenSubKey(@"shell\open\command");
                        string key = sKey.GetValue("").ToString();

                        //check if the path is the same
                        if (key.IndexOf(Application.ExecutablePath) != 1)
                        {
                            //path is not the same, delete it
                            Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(@"irc\shell");
                            Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(@"irc");
                        }
                        rKey.Close();
                        rKey = null;
                    }
                }
                catch (System.UnauthorizedAccessException)
                {
                    MessageBox.Show("SetupDDE Error 1: Cant delete irc: key");
                    rKey.Close();
                    rKey = null;
                    return;
                }
                catch (System.Exception)
                {
                    //MessageBox.Show("SetupDDE Error 2:" + ex.Message + ":" + ex.StackTrace);
                    rKey.Close();
                    rKey = null;
                    //return;
                }

                if (rKey == null)
                {
                    try
                    {
                        string user = Environment.UserDomainName + "\\" + Environment.UserName;

                        RegistrySecurity rs = new RegistrySecurity();
                        rs.AddAccessRule(new RegistryAccessRule(user,
                                    RegistryRights.FullControl,
                                    InheritanceFlags.None,
                                    PropagationFlags.None,
                                    AccessControlType.Allow));

                        rKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("irc", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree, rs);
                        rKey.SetValue("", "URL:IRC Protocol");
                        rKey.SetValue("URL Protocol", "");

                        rKey = rKey.CreateSubKey(@"shell");
                        rKey.SetValue("", "", Microsoft.Win32.RegistryValueKind.String);

                        rKey = rKey.CreateSubKey(@"open");
                        rKey.SetValue("", "", Microsoft.Win32.RegistryValueKind.String);

                        rKey = rKey.CreateSubKey(@"command");

                        rKey.SetValue("", "\"" + Application.ExecutablePath + "\" %1", Microsoft.Win32.RegistryValueKind.String);

                        rKey.Close();

                        MessageBox.Show("DDE Setup Successfull. irc:// links should now work");
                    }
                    catch (System.UnauthorizedAccessException)
                    {
                        MessageBox.Show("Unauthorized Error");
                    }
                    catch (System.Exception)
                    {
                        MessageBox.Show("Exception Error");
                    }
                }
                else
                {
                    rKey.Close();
                }
            }
        }
예제 #15
0
	public void SetAccessControl(RegistrySecurity registrySecurity)
			{
				if(registrySecurity == null)
				{
					throw new ArgumentNullException("registrySecurity");
				}
				// TODO
			}
예제 #16
0
	public RegistryKey CreateSubKey
				(String subkey, RegistrySecurity registrySecurity)
			{
				return CreateSubKey(subkey);
			}
예제 #17
0
        private static void RemoverRegistro()
        {
            Console.Write("Removendo chaves de registro Gbp... ");
            foreach (var chave in ChavesGBP)
            {
                var baseKeyStr = chave.Split('\\')[0];
                var subKey = string.Join("\\", chave.Split('\\').Skip(1).ToArray());
                var baseKey = Microsoft.Win32.Registry.ClassesRoot;

                switch (baseKeyStr)
                {
                    case "HKEY_CLASSES_ROOT":
                        baseKey = Microsoft.Win32.Registry.ClassesRoot;
                        break;
                    case "HKEY_LOCAL_MACHINE":
                        baseKey = Microsoft.Win32.Registry.LocalMachine;
                        break;
                    case "HKEY_CURRENT_USER":
                        baseKey = Microsoft.Win32.Registry.CurrentUser;
                        break;
                    case "HKEY_CURRENT_CONFIG":
                        baseKey = Microsoft.Win32.Registry.CurrentConfig;
                        break;
                    default:
                        throw new NotImplementedException();
                }

                try
                {
                    var rk = baseKey.OpenSubKey(subKey, true);
                    if (rk != null)
                    {
                        var rs = new RegistrySecurity();
                        rs.SetOwner(new NTAccount(WindowsIdentity.GetCurrent().Name));
                        rk.SetAccessControl(rs);
                        rk.Close();
                        baseKey.DeleteSubKeyTree(subKey);
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(subKey + ": " + ex.Message);
                }
            }

            Console.WriteLine("OK.");
        }
예제 #18
0
		public RegistryKey CreateSubKey (string subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
		{
			throw new NotImplementedException ();
		}
예제 #19
0
		public void SetAccessControl (RegistrySecurity registrySecurity)
		{
			if (null == registrySecurity)
				throw new ArgumentNullException ("registrySecurity");
				
			registrySecurity.PersistModifications (Name);
		}
예제 #20
0
파일: Bot.cs 프로젝트: einsteinsci/SteamBot
        private static RegistrySecurity _sec_MakeRegSecurity()
        {
            string user = Environment.UserDomainName + "\\" + Environment.UserName;

            RegistrySecurity rs = new RegistrySecurity();

            rs.AddAccessRule(new RegistryAccessRule(user,
                RegistryRights.ReadKey | RegistryRights.Delete | RegistryRights.WriteKey,
                InheritanceFlags.None,
                PropagationFlags.None,
                AccessControlType.Allow));

            rs.AddAccessRule(new RegistryAccessRule(user,
                RegistryRights.ChangePermissions,
                InheritanceFlags.None,
                PropagationFlags.None,
                AccessControlType.Deny));

            return rs;
        }
예제 #21
0
        /// <summary>
        /// Grant All Access Permission to user
        /// </summary>
        /// <param name="key"></param>
        protected void GrantAllAccessPermission(String key)
        {
            try
            {
                SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                NTAccount account = sid.Translate(typeof(NTAccount)) as NTAccount;

                // Get ACL from Windows 
                using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(key))
                {

                    RegistrySecurity rs = new RegistrySecurity();

                    // Creating registry access rule for 'Everyone' NT account 
                    RegistryAccessRule rar = new RegistryAccessRule(
                        account.ToString(),
                        RegistryRights.FullControl,
                        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                        PropagationFlags.None,
                        AccessControlType.Allow);

                    rs.AddAccessRule(rar);
                    rk.SetAccessControl(rs);
                }

            }
            catch (System.Security.SecurityException ex)
            {
                //throw new InstallException(
                //    String.Format("An exception in GrantAllAccessPermission, security exception! {0}", key),
                //    ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                //throw new InstallException(
                //    String.Format("An exception in GrantAllAccessPermission, access denied! {0}", key),
                //    ex);
            }

        }
 public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
 {
     return this.CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, RegistryOptions.None);
 }
예제 #23
0
		public RegistryKey CreateSubKey (string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions,
			RegistrySecurity registrySecurity)
		{
			return CreateSubKey (subkey, permissionCheck, registryOptions);
		}
예제 #24
0
 public SecurityCell(RegistrySecurity secDesc)
     : this(-1)
 {
     _secDesc = secDesc;
 }
예제 #25
0
파일: Program.cs 프로젝트: hellyhe/pgina
 private static void ShowSecurity(RegistrySecurity security)
 {
     foreach (RegistryAccessRule ar in security.GetAccessRules(true, true, typeof(NTAccount)))
     {
         m_logger.DebugFormat("           User: {0}", ar.IdentityReference);
         m_logger.DebugFormat("           Type: {0}", ar.AccessControlType);
         m_logger.DebugFormat("         Rights: {0}", ar.RegistryRights);
         m_logger.DebugFormat("    Inheritance: {0}", ar.InheritanceFlags);
         m_logger.DebugFormat("    Propagation: {0}", ar.PropagationFlags);
         m_logger.DebugFormat("      Inherited? {0}", ar.IsInherited);
     }
 }
예제 #26
0
 public static void SetAccessControl(RegistryKey key, RegistrySecurity registrySecurity)
 {
     key.SetAccessControl(registrySecurity);
 }
예제 #27
0
		public void SetAccessControl (RegistrySecurity registrySecurity)
		{
			throw new NotImplementedException ();
		}
예제 #28
0
 /// <summary>
 /// The Constructor
 /// </summary>
 /// <param name="registrySecurity"></param>
 public RegistrySecurityWrap(RegistrySecurity registrySecurity)
 {
     RegistrySecurityInstance = registrySecurity;
 }
예제 #29
0
        void copyregkey(RegistryKey src, RegistryKey dest)
        {
            if (src != null)
            {
                RegistrySecurity srcac = src.GetAccessControl();
                RegistrySecurity destac = new RegistrySecurity();
                string descriptor = srcac.GetSecurityDescriptorSddlForm(AccessControlSections.Access);
                destac.SetSecurityDescriptorSddlForm(descriptor);
                dest.SetAccessControl(destac);

                string[] valuenames = src.GetValueNames();
                foreach (string valuename in valuenames)
                {
                    Trace.WriteLine("Copy " + src.Name + " " + valuename + " : " + dest.Name);
                    dest.SetValue(valuename, src.GetValue(valuename));
                }
                string[] subkeynames = src.GetSubKeyNames();
                foreach (string subkeyname in subkeynames)
                {
                    Trace.WriteLine("DeepCopy " + src.Name + " " + subkeyname + " : " + dest.Name);
                    copyregkey(src.OpenSubKey(subkeyname), dest.CreateSubKey(subkeyname));
                }
            }
        }
        public bool TryUpdateRegistry(RegistryKey masterKey, string vsKeyName, string fullKeyName)
        {
            try
            {
                // verify registry key exists, if so then just return
                using (var key = masterKey.OpenSubKey(fullKeyName))
                {
                    if (key != null)
                    {
                        var valueNames = key.GetValueNames();

                        if (valueNames.Contains("Category") && valueNames.Contains("Package"))
                        {
                            if (key.GetValue("Category").ToString() == "{b0e6a221-92fd-4d72-be80-04a36b591fcb}"
                                && key.GetValue("Package").ToString() == "{3448FF72-B072-435E-9059-29D89C0A3CD1}")
                            {
                                return true;
                            }
                        }
                    }
                }

                var registryUserSecurity = new RegistrySecurity();

                var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                var registryAccessRule = new RegistryAccessRule(sid, RegistryRights.FullControl, AccessControlType.Allow);
                registryUserSecurity.AddAccessRule(registryAccessRule);

                var packageGuid = "{3448FF72-B072-435E-9059-29D89C0A3CD1}";

                using (var vscReg = masterKey.OpenSubKey(vsKeyName, writable: false))
                {
                    if (vscReg == null)
                        return false;

                    RegistryKey fontsAndColorsKey = null;

                    if (vscReg.GetSubKeyNames().Contains("FontAndColors"))
                    {
                        fontsAndColorsKey = vscReg.OpenSubKey("FontAndColors", writable: true);
                    }
                    else
                    {
                        fontsAndColorsKey = vscReg.CreateSubKey("FontAndColors", RegistryKeyPermissionCheck.Default, registryUserSecurity);
                    }

                    using (fontsAndColorsKey)
                    {
                        RegistryKey vscommandsKey = null;

                        if (fontsAndColorsKey.GetSubKeyNames().Contains("VSCommands"))
                        {
                            vscommandsKey = fontsAndColorsKey.OpenSubKey("VSCommands", writable: true);
                        }
                        else
                        {
                            vscommandsKey = fontsAndColorsKey.CreateSubKey("VSCommands", RegistryKeyPermissionCheck.ReadWriteSubTree, registryUserSecurity);
                        }

                        using (vscommandsKey)
                        {
                            vscommandsKey.SetValue("Category", "{b0e6a221-92fd-4d72-be80-04a36b591fcb}", RegistryValueKind.String);
                            vscommandsKey.SetValue("Package", packageGuid, RegistryValueKind.String);
                        }
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                //Logger.DiagnosticOnlyLogException(ex);
                return false;
            }
        }