private void CloseNewDesktop() { if (originalDesktop != null) { originalDesktop.Activate(); processFactory.StartupDesktop = originalDesktop; logger.Info($"Switched back to original desktop {originalDesktop}."); } else { logger.Warn($"No original desktop found to activate!"); } if (newDesktop != null) { newDesktop.Close(); logger.Info($"Closed new desktop {newDesktop}."); } else { logger.Warn($"No new desktop found to close!"); } explorerShell.Resume(); }
private void CreateNewDesktop() { originalDesktop = desktopFactory.GetCurrent(); logger.Info($"Current desktop is {originalDesktop}."); newDesktop = desktopFactory.CreateNew(nameof(SafeExamBrowser)); logger.Info($"Created new desktop {newDesktop}."); newDesktop.Activate(); processFactory.StartupDesktop = newDesktop; logger.Info("Successfully activated new desktop."); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { var handle = User32.OpenInputDesktop(0, false, (uint)AccessMask.DESKTOP_NONE); var name = string.Empty; 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(); }