void NativeMethods.ISecurityInformation3.OpenElevatedEditor(IntPtr hWnd, uint uPage) { SecurityPageType pgType = (SecurityPageType)(uPage & 0x0000FFFF); SecurityPageActivation pgActv = (SecurityPageActivation)((uPage >> 16) & 0x0000FFFF); System.Diagnostics.Debug.WriteLine(string.Format("OpenElevatedEditor: {0} - {1}", pgType, pgActv)); ObjInfoFlags lastElev = currentElevation; switch (pgActv) { case SecurityPageActivation.ShowDefault: currentElevation |= (ObjInfoFlags.PermsElevationRequired | ObjInfoFlags.ViewOnly); break; case SecurityPageActivation.ShowPermActivated: currentElevation |= (ObjInfoFlags.PermsElevationRequired | ObjInfoFlags.ViewOnly); pgType = SecurityPageType.AdvancedPermissions; break; case SecurityPageActivation.ShowAuditActivated: currentElevation |= ObjInfoFlags.AuditElevationRequired; pgType = SecurityPageType.Audit; break; case SecurityPageActivation.ShowOwnerActivated: currentElevation |= ObjInfoFlags.OwnerElevationRequired; pgType = SecurityPageType.Owner; break; case SecurityPageActivation.ShowEffectiveActivated: break; case SecurityPageActivation.ShowShareActivated: break; case SecurityPageActivation.ShowCentralPolicyActivated: break; default: break; } ShowDialog(hWnd, pgType, pgActv); currentElevation = lastElev; }
public RawSecurityDescriptor ShowDialog(IntPtr hWnd, SecurityPageType pageType = SecurityPageType.BasicPermissions, SecurityPageActivation pageAct = SecurityPageActivation.ShowDefault) { System.Diagnostics.Debug.WriteLine(string.Format("ShowDialog: {0} {1}", pageType, pageAct)); SecurityEventArg sd = null; SecurityEvent fn = delegate(SecurityEventArg e) { sd = e; }; try { OnSetSecurity += fn; if (System.Environment.OSVersion.Version.Major == 5 || (pageType == SecurityPageType.BasicPermissions && pageAct == SecurityPageActivation.ShowDefault)) { if (!NativeMethods.EditSecurity(hWnd, this)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } else { uint uPage = (uint)pageType & ((uint)pageAct << 16); NativeMethods.EditSecurityAdvanced(hWnd, this, uPage); } if (sd != null) { string sddl = NativeMethods.SecurityDescriptorPtrToSDLL(sd.SecurityDesciptor, sd.Parts); if (!string.IsNullOrEmpty(sddl)) { System.Diagnostics.Debug.WriteLine(string.Format("ShowDialog: Return: {0}", sddl)); return(new RawSecurityDescriptor(sddl)); } } } finally { OnSetSecurity -= fn; } System.Diagnostics.Debug.WriteLine(string.Format("ShowDialog: Return: null")); return(null); }