public static void PreventSleep() { if (SEBProcessHandler.SetThreadExecutionState(SEBProcessHandler.EXECUTION_STATE.ES_SYSTEM_REQUIRED | SEBProcessHandler.EXECUTION_STATE.ES_DISPLAY_REQUIRED | SEBProcessHandler.EXECUTION_STATE.ES_AWAYMODE_REQUIRED | SEBProcessHandler.EXECUTION_STATE.ES_CONTINUOUS) != (SEBProcessHandler.EXECUTION_STATE) 0) { return; } int num = (int)SEBProcessHandler.SetThreadExecutionState(SEBProcessHandler.EXECUTION_STATE.ES_SYSTEM_REQUIRED | SEBProcessHandler.EXECUTION_STATE.ES_DISPLAY_REQUIRED | SEBProcessHandler.EXECUTION_STATE.ES_CONTINUOUS); }
private void ExplorerStarted() { Logger.AddWarning("Windows explorer has been restarted!", this); var success = SEBProcessHandler.KillExplorerShell(); if (success) { Logger.AddInformation("Successfully terminated Windows explorer.", this); } else { Logger.AddError("Failed to terminate Windows explorer!", this, null); } }
private void ExplorerStarted(object sender, EventArgs e) { Logger.AddWarning("Windows Explorer has been restarted!", this); var success = SEBProcessHandler.KillExplorerShell(); if (success) { SEBClientInfo.SebWindowsClientForm?.Invoke(new Action(() => SEBClientInfo.SebWindowsClientForm?.PlaceFormOnDesktop(false))); Logger.AddInformation("Successfully terminated Windows Explorer.", this); } else { Logger.AddError("Failed to terminate Windows Explorer!", this, null); } }
public static bool KillExplorerShell() { try { IntPtr window = SEBProcessHandler.FindWindow("Shell_TrayWnd", (string)null); if (window != IntPtr.Zero) { SEBProcessHandler.PostMessage(window, 1460U, IntPtr.Zero, IntPtr.Zero); while (SEBProcessHandler.FindWindow("Shell_TrayWnd", (string)null) != IntPtr.Zero) { Thread.Sleep(500); } } return(true); } catch (Exception ex) { Logger.AddInformation("{0} {1}", (object)ex.Message, (Exception)null, (string)null); return(false); } }
public static void StartExplorerShell(bool waitForStartup = true) { if (!(SEBProcessHandler.FindWindow("Shell_TrayWnd", (string)null) == IntPtr.Zero)) { return; } string str = string.Format("{0}\\{1}", (object)Environment.GetEnvironmentVariable("WINDIR"), (object)"explorer.exe"); new Process() { StartInfo = { FileName = str, UseShellExecute = true, WorkingDirectory = Application.StartupPath, CreateNoWindow = true } }.Start(); for (int index = 0; index < 6; ++index) { Logger.AddInformation("waiting for explorer shell to get up " + (object)index + " seconds", (object)null, (Exception)null, (string)null); if (!(SEBProcessHandler.FindWindow("Shell_TrayWnd", (string)null) != IntPtr.Zero)) { Thread.Sleep(1000); } else { break; } } if (!waitForStartup) { return; } Logger.AddInformation("waiting for explorer shell to finish starting 6 seconds", (object)null, (Exception)null, (string)null); Thread.Sleep(6000); }