diff --git a/Core/Api/SessionEndpoints.cs b/Core/Api/SessionEndpoints.cs
index 32f875a..6f72b49 100644
--- a/Core/Api/SessionEndpoints.cs
+++ b/Core/Api/SessionEndpoints.cs
@@ -268,6 +268,12 @@ public record SessionResponse(
);
/// Usuario dedicado o perfil osms-* que ya no usa ninguna sesión.
+/// Cuenta local de Windows elegible para una sesión RDP.
+/// Nombre de la cuenta (SAM).
+/// Nombre completo, vacío si no tiene.
+/// true si es el usuario del escritorio físico de este PC.
+public record LocalUserResponse(string Name, string FullName, bool Console);
+
public record OrphanUserResponse(
/// Identificador para borrarlo (user:..., sid:... o dir:...).
string Key,
@@ -391,6 +397,16 @@ el directorio de perfiles. Los que tienen cuenta se pueden reutilizar al crear u
sesión aislada (ReuseIsolatedUser). ?sizes=true calcula el tamaño de cada perfil.
""");
+ // GET /api/sessions/local-users (antes que /{id:guid})
+ group.MapGet("/local-users", ListLocalUsers)
+ .WithName("ListLocalUsers")
+ .WithSummary("Usuarios locales de Windows para una sesión RDP")
+ .WithDescription("""
+ Cuentas locales normales, habilitadas y sin bloquear de este PC, sin los usuarios
+ dedicados osms-*. La UI las ofrece en una lista al crear una sesión RDP no aislada.
+ Console=true marca el usuario que tiene abierto el escritorio físico.
+ """);
+
// DELETE /api/sessions/isolated-users?key=...
group.MapDelete("/isolated-users", DeleteOrphanUser)
.WithName("DeleteOrphanIsolatedUser")
@@ -636,6 +652,15 @@ static Ok> ListOrphanUsers(StreamSessionService
o.Key, o.Name, o.AccountExists, o.ProfilePath, o.SizeBytes, o.SignedIn,
o.AccountExists ? SteamLoginProbe.GetState(o.Name) : null)));
+ static Ok> ListLocalUsers()
+ {
+ ConsoleSession.TryGetUser(out _, out var consoleDomain, out var consoleUser);
+ bool consoleIsLocal = string.Equals(consoleDomain, Environment.MachineName, StringComparison.OrdinalIgnoreCase);
+ return TypedResults.Ok(IsolatedUserManager.ListLocalAccounts().Select(u => new LocalUserResponse(
+ u.Name, u.FullName,
+ consoleIsLocal && string.Equals(u.Name, consoleUser, StringComparison.OrdinalIgnoreCase))));
+ }
+
static Results> DeleteOrphanUser(string key, StreamSessionService svc)
{
try
diff --git a/Core/Helpers/IsolatedUserManager.cs b/Core/Helpers/IsolatedUserManager.cs
index c7442c8..120bdc6 100644
--- a/Core/Helpers/IsolatedUserManager.cs
+++ b/Core/Helpers/IsolatedUserManager.cs
@@ -100,6 +100,16 @@ struct USER_INFO_1
public string? usri1_script_path;
}
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ struct USER_INFO_20
+ {
+ public string? usri20_name;
+ public string? usri20_full_name;
+ public string? usri20_comment;
+ public uint usri20_flags;
+ public uint usri20_user_id;
+ }
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct USER_INFO_1003
{
@@ -123,6 +133,8 @@ struct LOCALGROUP_MEMBERS_INFO_3
const int MAX_PREFERRED_LENGTH = -1;
const uint USER_PRIV_USER = 1;
const uint UF_SCRIPT = 0x0001; // obligatorio en NetUserAdd
+ const uint UF_ACCOUNTDISABLE = 0x0002;
+ const uint UF_LOCKOUT = 0x0010;
const uint UF_DONT_EXPIRE_PASSWD = 0x10000;
const string UserListKey =
@@ -403,6 +415,39 @@ internal static List ListManagedAccounts()
return names;
}
+ /// Cuenta local de Windows que se puede elegir para una sesión RDP.
+ internal sealed record LocalAccount(string Name, string FullName);
+
+ ///
+ /// Cuentas locales normales habilitadas y sin bloquear, sin las osms-* que gestiona
+ /// OpenStreamMS (esas van por la sesión aislada). Ordenadas por nombre.
+ ///
+ internal static List ListLocalAccounts()
+ {
+ var result = new List();
+ int resume = 0, rc;
+ int size = Marshal.SizeOf();
+ do
+ {
+ rc = NetUserEnum(null, 20, FILTER_NORMAL_ACCOUNT, out var buf, MAX_PREFERRED_LENGTH,
+ out int read, out _, ref resume);
+ if (rc is not (NERR_Success or ERROR_MORE_DATA)) break;
+ try
+ {
+ for (int i = 0; i < read; i++)
+ {
+ var u = Marshal.PtrToStructure(buf + i * size);
+ if (string.IsNullOrEmpty(u.usri20_name) || IsManagedName(u.usri20_name)) continue;
+ if ((u.usri20_flags & (UF_ACCOUNTDISABLE | UF_LOCKOUT)) != 0) continue;
+ result.Add(new LocalAccount(u.usri20_name, u.usri20_full_name ?? ""));
+ }
+ }
+ finally { NetApiBufferFree(buf); }
+ } while (rc == ERROR_MORE_DATA);
+ result.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
+ return result;
+ }
+
///
/// Usuarios dedicados sin sesión, perfiles de cuentas ya borradas y carpetas sueltas
/// osms-* en el directorio de perfiles. : usuarios de las sesiones.
diff --git a/Core/wwwroot/app.js b/Core/wwwroot/app.js
index 1557e49..ca8eaab 100644
--- a/Core/wwwroot/app.js
+++ b/Core/wwwroot/app.js
@@ -488,6 +488,40 @@ function updateIsolatedUi() {
if (reusing) byId('sess-ephemeral').checked = false;
}
+// ── Usuarios locales para la sesión RDP ────────────────────────────────────
+let localUsers = []; // GET /api/sessions/local-users
+
+async function loadLocalUsers() {
+ const res = await api('GET', '/api/sessions/local-users');
+ if (!res || !res.ok) return;
+ localUsers = await res.json();
+}
+
+// Rellena la lista de usuarios de Windows. Propone el primero que no use ninguna sesión
+// ni tenga abierto el escritorio de este PC; si no hay ninguno así, el primero.
+function fillLocalUserOptions() {
+ const sel = byId('sess-user');
+ if (!sel) return;
+ const current = sel.value;
+ const usedBy = new Map();
+ for (const s of sessions) {
+ if (s.username && (!s.domain || s.domain === '.')) usedBy.set(s.username.toLowerCase(), s.name);
+ }
+ const tag = u => {
+ const session = usedBy.get(u.name.toLowerCase());
+ if (session) return t('new.userTagInUse', { name: session });
+ return u.console ? t('new.userTagConsole') : '';
+ };
+ sel.innerHTML = localUsers.map(u => {
+ const label = u.fullName && u.fullName !== u.name ? `${u.name} (${u.fullName})` : u.name;
+ const extra = tag(u);
+ return ``;
+ }).join('');
+ const free = localUsers.find(u => !usedBy.has(u.name.toLowerCase()) && !u.console);
+ sel.value = localUsers.some(u => u.name === current) ? current : (free || localUsers[0] || {}).name || '';
+ byId('sess-user-none').style.display = localUsers.length ? 'none' : '';
+}
+
// Usuarios dedicados conservados que se pueden asignar a una sesión nueva.
function reusableUsers() {
return orphanUsers.filter(o => o.accountExists && !o.signedIn);
@@ -546,6 +580,8 @@ function openNewModal() {
stopRefresh();
suggestPorts();
loadOrphans().then(() => { fillReuseOptions(); updateIsolatedUi(); });
+ fillLocalUserOptions();
+ loadLocalUsers().then(() => { fillLocalUserOptions(); resetCredTest(); });
byId('sess-name').focus();
}
@@ -656,7 +692,7 @@ async function submitSession(e) {
if (needsCreds() && !credentialsTested) {
if (!byId('sess-user').value.trim() || !byId('sess-pass').value) {
fail(t('credTest.needCreds'));
- byId(byId('sess-user').value.trim() ? 'sess-pass' : 'sess-user').focus();
+ if (byId('sess-user').value) byId('sess-pass').focus();
return;
}
if (!await testCredentials()) { fail(t('new.errorTestCreds')); return; }
diff --git a/Core/wwwroot/index.html b/Core/wwwroot/index.html
index 15fd6a2..90c7a57 100644
--- a/Core/wwwroot/index.html
+++ b/Core/wwwroot/index.html
@@ -275,15 +275,11 @@