Skip to content

Instantly share code, notes, and snippets.

@solariz
Last active October 21, 2025 18:52
Show Gist options
  • Select an option

  • Save solariz/7a84894bd6e50b551ff6c621339e55a4 to your computer and use it in GitHub Desktop.

Select an option

Save solariz/7a84894bd6e50b551ff6c621339e55a4 to your computer and use it in GitHub Desktop.
tiny tool to move all Windows to the main Screen
/* tiny tool to move all Windows to the main Screen
* https://tcpip.wtf/en/rescreen-tool-to-move-all-windows-to-your-win-main-screen.htm
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace rescreen
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("rescreen - tiny window position mover.");
Console.WriteLine("more about me at: https://tcpip.wtf");
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
// only move Windows with a set title
if (!String.IsNullOrEmpty(process.MainWindowTitle) && !String.IsNullOrEmpty(process.ProcessName))
{
Console.WriteLine("+\tmoving: " + process.MainWindowTitle);
// Getting the Windows Handle
IntPtr id = process.MainWindowHandle;
// Getting dimensions of Window
RECT rct;
int width = 800; int height = 600;
if(GetWindowRect(id, out rct))
{
width = rct.Right - rct.Left;
height = rct.Bottom - rct.Top;
}
Program.MoveWindow(id, 100, 100, width, height, true);
}
}
}
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
}
}
@ikem-krueger

Copy link
Copy Markdown

Maybe you change the file extension to ".cs"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment