Fix Session 0 issue: spawn screen capture helper in user session
- CaptureModeRunner: captures desktop in user session via schtasks, sends JPEG frames over named pipe to service - RtcService: creates named pipe server, spawns helper via schtasks (same pattern as NotificationService), reads frames and forwards to WS - Program.cs: added --rdp-capture <pipeName> mode - Multi-monitor: captures all screens combined Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
62
agent-cs/CaptureModeRunner.cs
Normal file
62
agent-cs/CaptureModeRunner.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO.Pipes;
|
||||
|
||||
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
|
||||
public static class CaptureModeRunner
|
||||
{
|
||||
private static readonly ImageCodecInfo JpegCodec =
|
||||
ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid);
|
||||
|
||||
public static void Run(string pipeName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pipeName)) return;
|
||||
|
||||
try
|
||||
{
|
||||
using var pipe = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
|
||||
pipe.Connect(5000); // 5s timeout
|
||||
|
||||
var encParams = new EncoderParameters(1);
|
||||
encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 60L);
|
||||
|
||||
// Alle Screens zusammenführen (Multi-Monitor-Support)
|
||||
var allScreens = System.Windows.Forms.Screen.AllScreens;
|
||||
int left = allScreens.Min(s => s.Bounds.X);
|
||||
int top = allScreens.Min(s => s.Bounds.Y);
|
||||
int right = allScreens.Max(s => s.Bounds.X + s.Bounds.Width);
|
||||
int bottom = allScreens.Max(s => s.Bounds.Y + s.Bounds.Height);
|
||||
int totalW = right - left;
|
||||
int totalH = bottom - top;
|
||||
|
||||
while (pipe.IsConnected)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var bmp = new Bitmap(totalW, totalH, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
using (var g = Graphics.FromImage(bmp))
|
||||
g.CopyFromScreen(left, top, 0, 0, new Size(totalW, totalH));
|
||||
|
||||
byte[] jpeg;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
bmp.Save(ms, JpegCodec, encParams);
|
||||
jpeg = ms.ToArray();
|
||||
}
|
||||
|
||||
// Länge (4 Bytes LE) + JPEG-Daten
|
||||
pipe.Write(BitConverter.GetBytes(jpeg.Length));
|
||||
pipe.Write(jpeg);
|
||||
pipe.Flush();
|
||||
}
|
||||
catch { break; }
|
||||
|
||||
Thread.Sleep(150); // ~6-7 fps
|
||||
}
|
||||
}
|
||||
catch { /* Pipe nicht verfügbar oder Timeout → Exit */ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user