RegistryKey разрешения - C#

Узнай цену своей работы

Формулировка задачи:

Возможно ли через RegistryKey перечислить привилегии?

Решение задачи: «RegistryKey разрешения»

textual
Листинг программы
  1. public static void ViewRegKeyRights()
  2. {
  3.     // Get security information from a registry key.
  4.     using (RegistryKey regKey =
  5.         Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MyCompany\MyApp"))
  6.     {
  7.         RegistrySecurity regSecurity = regKey.GetAccessControl();
  8.         DisplayRegKeySecurityInfo(regSecurity);
  9.     }
  10. }
  11.  
  12. public static void DisplayRegKeySecurityInfo(RegistrySecurity regSec)
  13. {
  14.     Console.WriteLine("GetSecurityDescriptorSddlForm: {0}",
  15.         regSec.GetSecurityDescriptorSddlForm(AccessControlSections.All));
  16.  
  17.     foreach (RegistryAccessRule ace in
  18.             regSec.GetAccessRules(true, true, typeof(NTAccount)))
  19.     {
  20.         Console.WriteLine("\tIdentityReference.Value: {0}",
  21.                           ace.IdentityReference.Value);
  22.         Console.WriteLine("\tAccessControlType: {0}", ace.AccessControlType);
  23.         Console.WriteLine("\tRegistryRights: {0}", ace.RegistryRights.ToString());
  24.         Console.WriteLine("\tInheritanceFlags: {0}", ace.InheritanceFlags);
  25.         Console.WriteLine("\tIsInherited: {0}", ace.IsInherited);
  26.         Console.WriteLine("\tPropagationFlags: {0}", ace.PropagationFlags);
  27.  
  28.         Console.WriteLine("-----------------\r\n\r\n");
  29.     }
  30.  
  31.     foreach (RegistryAuditRule ace in
  32.             regSec.GetAuditRules(true, true, typeof(NTAccount)))
  33.     {
  34.         Console.WriteLine("\tIdentityReference.Value: {0}",
  35.                           ace.IdentityReference.Value);
  36.         Console.WriteLine("\tAuditFlags: {0}", ace.AuditFlags);
  37.         Console.WriteLine("\tRegistryRights: {0}", ace.RegistryRights.ToString());
  38.         Console.WriteLine("\tInheritanceFlags: {0}", ace.InheritanceFlags);
  39.         Console.WriteLine("\tIsInherited: {0}", ace.IsInherited);
  40.         Console.WriteLine("\tPropagationFlags: {0}", ace.PropagationFlags);
  41.  
  42.         Console.WriteLine("-----------------\r\n\r\n");
  43.     }
  44.     Console.WriteLine("GetGroup(typeof(NTAccount)).Value: {0}",
  45.                       regSec.GetGroup(typeof(NTAccount)).Value);
  46.     Console.WriteLine("GetOwner(typeof(NTAccount)).Value: {0}",
  47.                       regSec.GetOwner(typeof(NTAccount)).Value);
  48.  
  49.     Console.WriteLine("---------------------------------------\r\n\r\n\r\n");
  50. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.429 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут