Restore SEBPatch
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
* Copyright (c) 2025 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@@ -49,7 +49,41 @@ namespace SafeExamBrowser.WindowsApi.Desktops
|
||||
|
||||
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
var handle = User32.OpenInputDesktop(0, false, (uint) AccessMask.DESKTOP_NONE);
|
||||
var name = default(string);
|
||||
var nameLength = 0;
|
||||
|
||||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
User32.GetUserObjectInformation(handle, Constant.UOI_NAME, IntPtr.Zero, 0, ref nameLength);
|
||||
|
||||
var namePointer = Marshal.AllocHGlobal(nameLength);
|
||||
var success = User32.GetUserObjectInformation(handle, Constant.UOI_NAME, namePointer, nameLength, ref nameLength);
|
||||
|
||||
if (success)
|
||||
{
|
||||
name = Marshal.PtrToStringAnsi(namePointer);
|
||||
Marshal.FreeHGlobal(namePointer);
|
||||
|
||||
if (name?.Equals(desktop.Name, StringComparison.OrdinalIgnoreCase) != true)
|
||||
{
|
||||
logger.Warn($"Detected desktop switch to '{name}' [{handle}], trying to reactivate {desktop}...");
|
||||
desktop.Activate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn("Failed to get name of currently active desktop!");
|
||||
}
|
||||
|
||||
User32.CloseDesktop(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn("Failed to get currently active desktop!");
|
||||
}
|
||||
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user