/// <summary> /// Gets the security descriptor for the item specified by <paramref name="path"/>. /// </summary> /// /// <param name="path"> /// The path to the item. /// </param> /// /// <param name="sections"> /// Specifies the parts of a security descriptor to retrieve. /// </param> /// /// <returns> /// Nothing. An object that represents the security descriptor for the item /// specified by path is written to the WriteSecurityDescriptorObject method. /// </returns> public void GetSecurityDescriptor(string path, AccessControlSections sections) { ObjectSecurity sd = null; IRegistryWrapper key = null; // Validate input first. if (String.IsNullOrEmpty(path)) { throw PSTraceSource.NewArgumentNullException("path"); } if ((sections & ~AccessControlSections.All) != 0) { throw PSTraceSource.NewArgumentException("sections"); } path = NormalizePath(path); key = GetRegkeyForPathWriteIfError(path, false); if (key != null) { try { sd = key.GetAccessControl(sections); } catch (System.Security.SecurityException e) { WriteError(new ErrorRecord(e, e.GetType().FullName, ErrorCategory.PermissionDenied, path)); return; } WriteSecurityDescriptorObject(sd, path); } }