Created
May 27, 2025 12:53
-
-
Save AdmiralSnyder/603213abde766e69e4e69a75028c1ee4 to your computer and use it in GitHub Desktop.
Updating a specific rdp file so that the screen indexes for the selectedmonitors parameter are adjusted correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! dotnet run | |
#:sdk Microsoft.NET.Sdk | |
#:property UseWindowsForms True | |
#:property TargetFramework net10.0-windows | |
using System.Windows.Forms; | |
var screens = Screen.AllScreens.Select(scr => (Screen: scr, Index : int.Parse(scr.DeviceName.Split("DISPLAY").Last()) - 1)); | |
int firstScreenIdx = -1; | |
List<int> otherScreens = []; | |
foreach (var scr in screens.Where(x => x.Screen.WorkingArea.X >= 0).OrderBy(x => x.Index)) | |
{ | |
if (scr.Screen.WorkingArea.X == 0 && scr.Screen.WorkingArea.Y == 0) | |
{ | |
firstScreenIdx = scr.Index; | |
} | |
else | |
{ | |
otherScreens.Add(scr.Index); | |
} | |
//Console.WriteLine($"{scr.Index} : {scr.Screen.WorkingArea} {scr.Screen.DeviceName}"); | |
} | |
var fileName = @"C:\Users\Alexa\OneDrive\Desktop\codierdpalex ALLSCREENS 1.rdp"; | |
var lines = File.ReadAllLines(fileName, System.Text.Encoding.Unicode).ToList(); | |
var selectedmonitorsLine = lines.First(l => l.StartsWith("selectedmonitors:s:")); | |
var lineIndex = lines.IndexOf(selectedmonitorsLine); | |
lines[lineIndex] = $"selectedmonitors:s: {firstScreenIdx},{string.Join(",", otherScreens)}"; | |
File.WriteAllLines(fileName, lines, System.Text.Encoding.Unicode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment