08/04/2026

Windows – remote scan

  • First the registry should be edittted by creating “Install-ScanMenu.reg”. and add it to registry.

        We need to decide what name and where we will locate the script.and we need to edit this reg file before 

  • Also the ssh should be enabled to the host.

Önce registry

Windows Registry Editor Version 5.00

; ── Right-click on a FOLDER ──────────────────────────────────
[HKEY_CLASSES_ROOT\Directory\shell\ScanDocumentHere]
@="Scan Document Here"
"Icon"="imageres.dll,-174"

[HKEY_CLASSES_ROOT\Directory\shell\ScanDocumentHere\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Users\\User\\Scan-Document.ps1\" \"%V\""

; ── Right-click on the DESKTOP background ────────────────────
[HKEY_CLASSES_ROOT\Directory\Background\shell\ScanDocumentHere]
@="Scan Document Here"
"Icon"="imageres.dll,-174"

[HKEY_CLASSES_ROOT\Directory\Background\shell\ScanDocumentHere\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Users\\User\\Scan-Document.ps1\" \"%V\""

Burada önemli olan scriptin isi ve yerini koymadan eklemek lazim.


# ============================================================
#  Scan-Document.ps1
#  Right-click a folder "Scan Document Here"
#  Requires: Windows 10/11 with OpenSSH client enabled
# ============================================================

$SSH_USER   = "root1"                        # your Linux username
$SSH_HOST   = "192.168.0.4"                      # hostname or IP of your Linux machine
$SSH_PORT   = 22                        # change if you use a non-standard port
$DEVICE     = "pixma:04A918A2_4DB3BA"        # from: scanimage -L
$RESOLUTION = 300
$MODE       = "Color"
$WIDTH      = 210                            # mm  (210x297 = A4)
$HEIGHT     = 297
$FORMAT     = "jpeg"
 
# Determine save folder:
#   - If a folder path was passed as argument (right-click on folder) use it
#   - Otherwise fall back to the user's Pictures\Scans folder
if ($args.Count -gt 0 -and (Test-Path $args[0] -PathType Container)) {
    $SaveFolder = $args[0]
} else {
    $SaveFolder = Join-Path ([Environment]::GetFolderPath("MyPictures")) "Scans"
}
 
# Make sure the local save folder exists
New-Item -ItemType Directory -Force -Path $SaveFolder | Out-Null
 
# Build a timestamped filename so scans never overwrite each other
$Timestamp  = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$RemoteFile = "/tmp/scan_$Timestamp.$FORMAT"
$LocalFile  = Join-Path $SaveFolder "scan_$Timestamp.$FORMAT"
 
Write-Host ""
Write-Host "=== Scan-Document ===" -ForegroundColor Cyan
Write-Host "Scanner : $DEVICE"
Write-Host "Save to : $LocalFile"
Write-Host ""
 
# STEP 1: run scanimage on the Linux machine 
Write-Host "Starting scan..." -ForegroundColor Yellow

$WaitCmd = 'for i in 1 2 3 4 5 6 7 8 9 10; do scanimage -L 2>/dev/null | grep -q pixma && exit 0; echo "Waiting..."; sleep 3; done; exit 1'
ssh -p $SSH_PORT "${SSH_USER}@${SSH_HOST}" $WaitCmd
 
$ScanCmd = "scanimage " +
    "--device '$DEVICE' " +
    "--format=$FORMAT " +
    "--resolution=$RESOLUTION " +
    "--mode=$MODE " +
    "-l 0 -t 0 " +
    "-x $WIDTH -y $HEIGHT " +
    "--output-file=$RemoteFile"
 
ssh -p $SSH_PORT "${SSH_USER}@${SSH_HOST}" $ScanCmd
 
if ($LASTEXITCODE -ne 0) {
    Write-Host ""
    Write-Host "ERROR: Scan failed (exit code $LASTEXITCODE)." -ForegroundColor Red
    Write-Host "Check that the scanner is on and the device string is correct."
    Read-Host "Press Enter to close"
    exit 1
}
 
Write-Host "Scan complete. Downloading file..." -ForegroundColor Yellow
 
# STEP 2: copy the scanned file to the Windows machine
scp -P $SSH_PORT "${SSH_USER}@${SSH_HOST}:${RemoteFile}" "$LocalFile"
 
if ($LASTEXITCODE -ne 0) {
    Write-Host ""
    Write-Host "ERROR: Could not download the scanned file." -ForegroundColor Red
    Read-Host "Press Enter to close"
    exit 1
}
 
# STEP 3: clean up the temporary file on Linux 
ssh -p $SSH_PORT "${SSH_USER}@${SSH_HOST}" "rm -f $RemoteFile"
 
Write-Host ""
Write-Host "Done! File saved to:" -ForegroundColor Green
Write-Host "  $LocalFile" -ForegroundColor Green
Write-Host ""
 
# Open the scanned file automatically
Start-Process $LocalFile
 
Start-Sleep -Seconds 2   # keep the window visible briefly

Win10 : Once it is done we have to right click to a folder and select “Scan Document Here”

Win11 : However, there is one Windows 11 specific gotcha: the new right-click menu. By default Windows 11 shows a simplified context menu first, and your custom entry will be hidden under “Show more options” (the classic menu).