Fix pipe ACL: switch from named pipe to TCP loopback
Named pipe created by SYSTEM service denied connection from user process. TCP loopback socket (127.0.0.1:random) has no cross-session ACL issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO.Pipes;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ITNexusAgent;
|
||||
|
||||
// Läuft als User-Prozess (via schtasks), nicht als SYSTEM-Service
|
||||
// Captured den Desktop und schickt JPEG-Frames via Named Pipe an den Service
|
||||
// Captured den Desktop und schickt JPEG-Frames via TCP Loopback an den Service
|
||||
public static class CaptureModeRunner
|
||||
{
|
||||
private static readonly ImageCodecInfo JpegCodec =
|
||||
ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid);
|
||||
|
||||
public static void Run(string pipeName)
|
||||
public static void Run(string portStr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pipeName)) return;
|
||||
if (!int.TryParse(portStr, out var port) || port <= 0) return;
|
||||
|
||||
try
|
||||
{
|
||||
using var pipe = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
|
||||
pipe.Connect(5000); // 5s timeout
|
||||
using var tcp = new TcpClient();
|
||||
tcp.Connect("127.0.0.1", port);
|
||||
var stream = tcp.GetStream();
|
||||
|
||||
var encParams = new EncoderParameters(1);
|
||||
encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 60L);
|
||||
@@ -32,7 +33,7 @@ public static class CaptureModeRunner
|
||||
int totalW = right - left;
|
||||
int totalH = bottom - top;
|
||||
|
||||
while (pipe.IsConnected)
|
||||
while (tcp.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -47,16 +48,16 @@ public static class CaptureModeRunner
|
||||
jpeg = ms.ToArray();
|
||||
}
|
||||
|
||||
// Länge (4 Bytes LE) + JPEG-Daten
|
||||
pipe.Write(BitConverter.GetBytes(jpeg.Length));
|
||||
pipe.Write(jpeg);
|
||||
pipe.Flush();
|
||||
// 4-Byte Länge (LE) + JPEG-Daten
|
||||
stream.Write(BitConverter.GetBytes(jpeg.Length));
|
||||
stream.Write(jpeg);
|
||||
stream.Flush();
|
||||
}
|
||||
catch { break; }
|
||||
|
||||
Thread.Sleep(150); // ~6-7 fps
|
||||
}
|
||||
}
|
||||
catch { /* Pipe nicht verfügbar oder Timeout → Exit */ }
|
||||
catch { /* Verbindung fehlgeschlagen → Exit */ }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user