English | 简体中文
Resize any Windows window to an exact pixel size and center it, or place it at exact coordinates. A single PowerShell script with nothing to install.
.\Set-WindowRect.ps1 -ProcessName notepad # Notepad → 1280×720, centered
.\Set-WindowRect.ps1 -ProcessName pcsx2-qt -ClientArea # content area exactly 1280×720, centeredDragging is never pixel-exact, and even resizing from code has pitfalls. This script handles them:
| Pitfall | What goes wrong | How the script handles it |
|---|---|---|
| Frame or content? | "1280×720" can mean the whole window or just the area inside the title bar and borders. With a 1280×720 frame, the content area is usually only about 1277×680 | Sizes the visible frame by default; -ClientArea sizes the content area |
| Invisible borders | Windows 10/11 windows have ~7 px invisible resize borders, so the reported window size is larger than what you see and centering is off | Uses the real visible frame from DWM |
| Display scaling | At 125%/150% scaling, different programs see different coordinate units | Works in physical pixels (Per-Monitor DPI Aware V2) |
| Taskbar | Centering on the whole screen lets the taskbar cover part of the window | Centers in the work area (excluding the taskbar) by default; -FullMonitor uses the whole screen |
| Maximized windows | A maximized window can't be resized | Restores it first |
| Menu bar wrapping | Changing the width can wrap the menu bar and change the content height | Re-measures and corrects, up to 3 passes |
- Windows 10 1703 or later / Windows 11
- Windows PowerShell 5.1 (built in) or PowerShell 7+
Download Set-WindowRect.ps1 and run it in PowerShell.
# By process name (wildcards allowed, with or without .exe)
.\Set-WindowRect.ps1 -ProcessName notepad
# By window title (matches "contains" when no wildcard is given)
.\Set-WindowRect.ps1 -Title "Chrome"
# By window handle (when several windows match, the script prints their handles)
.\Set-WindowRect.ps1 -Handle 132456
# Nothing specified: click the target window within 3 seconds; the foreground window is used
.\Set-WindowRect.ps1Don't know the process name or title? List the windows first:
.\Set-WindowRect.ps1 -List
.\Set-WindowRect.ps1 -List -ProcessName chrome Handle Process 外框 客户区 位置 Title
------ ------- ---- ------ ---- -----
132456 Notepad 1280×720 1277×680 (320, 150) Untitled - Notepad
(The script's output labels are in Chinese: 外框 = visible frame, 客户区 = client/content area, 位置 = position.)
# Custom size, centered
.\Set-WindowRect.ps1 -ProcessName notepad -Width 1600 -Height 900
# Content area exactly 1920×1080 (games, emulators, screen recording)
.\Set-WindowRect.ps1 -ProcessName obs64 -Width 1920 -Height 1080 -ClientArea
# Place at exact coordinates (top-left of the visible frame); give only -X or -Y to keep the other axis centered
.\Set-WindowRect.ps1 -ProcessName notepad -X 0 -Y 0
# Center on the whole screen, including the taskbar area
.\Set-WindowRect.ps1 -ProcessName notepad -FullMonitorThe window is centered on the monitor it is currently on.
| Parameter | Default | Description |
|---|---|---|
-ProcessName |
Match by process name; wildcards allowed | |
-Title |
Match by window title | |
-Handle |
Target a specific window handle | |
-Width / -Height |
1280 / 720 |
Target size in pixels |
-ClientArea |
off | Apply the size to the content area instead of the frame |
-X / -Y |
centered | Top-left corner of the visible frame |
-FullMonitor |
off | Center on the whole screen instead of the work area |
-Delay |
3 |
Seconds to wait for you to switch windows when no target is given |
-List |
List windows instead of resizing |
After running, the script prints the actual result, for example:
可见外框: 1282×760 位置 (319, 130)
客户区 : 1280×720
(可见外框 = visible frame, 位置 = position, 客户区 = client area.)
Windows blocks downloaded scripts by default. Pick one:
# This run only
powershell -ExecutionPolicy Bypass -File .\Set-WindowRect.ps1 -ProcessName notepad
# Or remove the "downloaded from the internet" mark and allow local scripts for your user
Unblock-File .\Set-WindowRect.ps1
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedCreate a desktop shortcut with this target:
powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "D:\path\to\Set-WindowRect.ps1" -ProcessName notepad -ClientArea
Without -ProcessName, double-click the shortcut and then click the target window within 3 seconds. You can also assign a shortcut key in the shortcut's properties.
- Only each process's main window is matched. If a process has several top-level windows, find the handle with
-Listand use-Handle. - Windows with minimum/maximum size limits, fixed-size dialogs, and games in exclusive fullscreen may not accept the target size; the script warns when that happens.
- Older programs that aren't DPI-aware are scaled up by Windows, so their own idea of 1280×720 is larger on screen. This script measures physical pixels on screen.
- To resize a window running as administrator, run the script from an elevated PowerShell.