Repository navigation
How it works
m4bwav edited this page Nov 18, 2026
·
2 revisions
-
src/Save-ClipboardImage.ps1reads the clipboard and writes a file. It works on its own from any PowerShell prompt. -
src/Install-PasteImageMenu.ps1copies the first script to%LOCALAPPDATA%\paste-image-file\and writes two registry keys that make Explorer run that copy. The downloaded folder is not needed afterwards.
Both live under HKEY_CURRENT_USER\Software\Classes\Directory, which only affects the current user and needs no admin rights:
| Key | Shown when you right-click | Placeholder |
|---|---|---|
shell\PasteImageFile |
a folder icon |
%1 = that folder |
Background\shell\PasteImageFile |
empty space inside a folder window |
%V = the open folder |
Each key has a default value (the menu text), an Icon value (PowerShell's icon) and a command subkey holding the command line.
"C:\Windows\System32\conhost.exe" --headless "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
-NoProfile -STA -ExecutionPolicy Bypass -WindowStyle Hidden
-File "%LOCALAPPDATA%\paste-image-file\Save-ClipboardImage.ps1" -Path "%1." -Gui
-
conhost.exe --headlessstarts PowerShell with a pseudo-console and no window. Without it, Windows creates a console window (or a Windows Terminal tab, if Terminal is the default) before PowerShell can hide it, so-WindowStyle Hiddenalone flashes.--headlessis the flag Windows uses internally for ConPTY; it exists on Windows 10 1809 and later. Ifconhost.exeis missing, the installer falls back to-WindowStyle Hidden. - Windows PowerShell 5.1, not PowerShell 7: it ships with every Windows, so the menu works without anything else installed.
-
-STA: the Windows Forms clipboard API only works in a single-threaded apartment. -
-ExecutionPolicy Bypassfor this process only, so a downloaded script runs without changing the machine's policy. -
"%1.", with a trailing dot: for a drive root,%1isD:\, and"D:\"on a command line means the backslash escapes the closing quote, so PowerShell receives a broken argument."D:\."is safe; the script strips the dot again. -
-Gui: with no console, errors would be invisible, so the script shows them in a message box instead.
The script asks for formats in this order and uses the first one present:
-
PNG, a registered clipboard format holding a PNG file stream. Chromium browsers and Firefox write it on Copy image. It is the only common format that keeps alpha. When the target is.pngthe stream is copied straight to disk. -
CF_BITMAP/CF_DIB, viaClipboard.GetImage(). Screenshots and most desktop programs. No alpha in practice. -
HTML Format. Some pages copy only markup. The first<img src="...">is fetched withInvoke-WebRequest, or decoded when it isdata:image/...;base64,.... Relative URLs andfile:URLs are refused.
JPEG output is flattened onto white first, because JPEG has no alpha and transparent pixels would otherwise turn black.
A folder (or no -Path) means clipboard_yyyyMMdd_HHmmss.png. If the name exists, -1, -2 ... is appended, so a quick double paste never overwrites anything. A path with no extension gets .png.
paste-image-file - MIT licence - report an issue