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(); }