public void RemoveDesktopPermission(string userOrGroupName) { SafeHandle shWindowStation = new NonReleasingSafeHandle(GetProcessWindowStation(), false); var ws = new WindowStationSecurity(shWindowStation); ws.RemoveAccessRule(new AccessRule<NativeMethods.WindowStationRights>(userOrGroupName, NativeMethods.WindowStationRights.AllAccess, AccessControlType.Allow)); ws.AcceptChanges(); SafeHandle shDesktopThread = new NonReleasingSafeHandle(GetThreadDesktop(GetCurrentThreadId()), false); var ds = new DesktopSecurity(shDesktopThread); ds.RemoveAccessRule(new AccessRule<NativeMethods.DesktopRights>(userOrGroupName, NativeMethods.DesktopRights.AllAccess, AccessControlType.Allow)); ds.AcceptChanges(); }
public void RemoveDesktopPermission(string userOrGroupName) { SafeHandle shWindowStation = new NonReleasingSafeHandle(GetProcessWindowStation(), false); var ws = new WindowStationSecurity(shWindowStation); ws.RemoveAccessRule(new AccessRule <NativeMethods.WindowStationRights>(userOrGroupName, NativeMethods.WindowStationRights.AllAccess, AccessControlType.Allow)); ws.AcceptChanges(); SafeHandle shDesktopThread = new NonReleasingSafeHandle(GetThreadDesktop(GetCurrentThreadId()), false); var ds = new DesktopSecurity(shDesktopThread); ds.RemoveAccessRule(new AccessRule <NativeMethods.DesktopRights>(userOrGroupName, NativeMethods.DesktopRights.AllAccess, AccessControlType.Allow)); ds.AcceptChanges(); }
public void RemoveDesktopPermission() { IntPtr hWindowStation = GetProcessWindowStation(); var ws = new WindowStationSecurity(hWindowStation, AccessControlSections.Access); ws.RemoveAccessRule(new WindowStationAccessRule(userName, WindowStationRights.AllAccess, AccessControlType.Allow)); ws.AcceptChanges(); IntPtr hDesktopThread = GetThreadDesktop(GetCurrentThreadId()); var ds = new DesktopSecurity(hDesktopThread, AccessControlSections.Access); ds.RemoveAccessRule(new DesktopAccessRule(userName, DesktopRights.AllAccess, AccessControlType.Allow)); ds.AcceptChanges(); }
public void RemoveDesktopPermission() { try { IntPtr hWinSta = NativeMethods.GetProcessWindowStation(); var ws = new WindowStationSecurity(hWinSta, AccessControlSections.Access); ws.RemoveAccessRule(new WindowStationAccessRule(userName, WindowStationRights.AllAccess, AccessControlType.Allow)); ws.AcceptChanges(); IntPtr hDesk = NativeMethods.GetThreadDesktop(NativeMethods.GetCurrentThreadId()); var ds = new DesktopSecurity(hDesk, AccessControlSections.Access); ds.RemoveAccessRule(new DesktopAccessRule(userName, DesktopRights.AllAccess, AccessControlType.Allow)); ds.AcceptChanges(); } catch (Exception ex) { log.ErrorException("Exception removing desktop permissions!", ex); } }