public static void RunWithPrivilege( string privilege, bool enabled, PrivilegedCallback callback, object state) { if ( callback == null ) { throw new ArgumentNullException( "callback" ); } Privilege p = new Privilege( privilege ); try { if (enabled) { p.Enable(); } else { p.Disable(); } callback(state); } catch { p.Revert(); throw; } finally { p.Revert(); } }