@echo off
title AzzoDatas Local Explorer Bridge (Port 24281)
echo ============================================================================
echo   Pont Local AzzoDatas pour Poste Distant (Ouvre Explorer et Fichiers F:\)
echo ============================================================================
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class AzzoWin32 { [DllImport(\"user32.dll\")] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport(\"user32.dll\")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport(\"user32.dll\")] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); }' -ErrorAction SilentlyContinue; $l = [System.Net.HttpListener]::new(); $l.Prefixes.Add('http://127.0.0.1:24281/'); $l.Start(); Write-Host '[OK] Pont actif sur http://127.0.0.1:24281 (Fenetre Explorer Unique) - Laissez cette fenetre reduite.' -ForegroundColor Green; while ($l.IsListening) { try { $c = $l.GetContext(); $req = $c.Request; $res = $c.Response; $res.Headers.Add('Access-Control-Allow-Origin', '*'); $res.Headers.Add('Access-Control-Allow-Methods', 'POST, GET, OPTIONS'); $res.Headers.Add('Access-Control-Allow-Headers', 'Content-Type'); if ($req.HttpMethod -eq 'OPTIONS') { $res.StatusCode = 200; $res.Close(); continue }; $act = $req.QueryString['action']; $p = $req.QueryString['path']; $buf = [System.Text.Encoding]::UTF8.GetBytes('{\"ok\":true}'); $res.ContentType = 'application/json'; $res.OutputStream.Write($buf, 0, $buf.Length); $res.Close(); [AzzoWin32]::keybd_event(0x12, 0, 0, [UIntPtr]::Zero); [AzzoWin32]::keybd_event(0x12, 0, 2, [UIntPtr]::Zero); $sh = New-Object -ComObject Shell.Application; $ws = @($sh.Windows() | Where-Object { $_.Document -and $_.Document.Folder }); if ($act -eq 'reveal' -and $p) { $dir = [System.IO.Path]::GetDirectoryName($p); $fn = [System.IO.Path]::GetFileName($p); $win = $null; foreach ($w in $ws) { try { if ($w.Document.Folder.Self.Path -ieq $dir) { $win = $w; break } } catch {} }; if (-not $win -and $ws.Count -gt 0) { $win = $ws[$ws.Count - 1]; $win.Navigate2($dir); for ($i = 0; $i -lt 25; $i++) { Start-Sleep -Milliseconds 80; try { if ($win.Document.Folder.Self.Path -ieq $dir) { break } } catch {} } }; if ($win) { try { $it = $win.Document.Folder.ParseName($fn); if ($it) { $win.Document.SelectItem($it, 29) }; $h = [IntPtr]$win.HWND; [AzzoWin32]::ShowWindow($h, 9) | Out-Null; [AzzoWin32]::SetForegroundWindow($h) | Out-Null } catch {} } else { Start-Process explorer.exe -ArgumentList ('/select,\"' + $p + '\"'); Start-Sleep -Milliseconds 300; $ws2 = @($sh.Windows()); if ($ws2.Count -gt 0) { $h = [IntPtr]$ws2[$ws2.Count - 1].HWND; [AzzoWin32]::ShowWindow($h, 9) | Out-Null; [AzzoWin32]::SetForegroundWindow($h) | Out-Null } } } elseif ($act -eq 'open' -and $p) { Start-Process rundll32.exe -ArgumentList ('url.dll,FileProtocolHandler', $p) } elseif ($act -eq 'folder' -and $p) { if ($ws.Count -gt 0) { $win = $ws[$ws.Count - 1]; if ($win.Document.Folder.Self.Path -ine $p) { $win.Navigate2($p) }; $h = [IntPtr]$win.HWND; [AzzoWin32]::ShowWindow($h, 9) | Out-Null; [AzzoWin32]::SetForegroundWindow($h) | Out-Null } else { Start-Process explorer.exe -ArgumentList ('\"' + $p + '\"'); Start-Sleep -Milliseconds 300; $ws2 = @($sh.Windows()); if ($ws2.Count -gt 0) { $h = [IntPtr]$ws2[$ws2.Count - 1].HWND; [AzzoWin32]::ShowWindow($h, 9) | Out-Null; [AzzoWin32]::SetForegroundWindow($h) | Out-Null } } } } catch {} }"
pause
