From 2263c9ca0ff22d04e044e5e3fcca4965cf214c24 Mon Sep 17 00:00:00 2001 From: "Carl J. Bialorucki" Date: Mon, 8 Jun 2026 08:06:32 -0500 Subject: [PATCH] [USERINIT] Start shell from profile path When the shell is assigned to cmd.exe, open to the logged in user's profile path. This appears to match the behavior of Windows Server 2003 userinit. It is also a prerequisite for ReactOS Server Core. --- base/system/userinit/userinit.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/base/system/userinit/userinit.c b/base/system/userinit/userinit.c index b6a67c9409c..882be9324a4 100644 --- a/base/system/userinit/userinit.c +++ b/base/system/userinit/userinit.c @@ -21,7 +21,7 @@ * PROJECT: ReactOS Userinit Logon Application * FILE: base/system/userinit/userinit.c * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net) - * Hervé Poussineau (hpoussin@reactos.org) + * HervĂ© Poussineau (hpoussin@reactos.org) */ #include "userinit.h" @@ -184,7 +184,9 @@ StartProcess( { STARTUPINFO si; PROCESS_INFORMATION pi; - WCHAR ExpandedCmdLine[MAX_PATH]; + WCHAR ExpandedCmdLine[MAX_PATH], ProfilePath[MAX_PATH]; + HANDLE hToken; + PWCHAR WorkingDir = NULL; ExpandEnvironmentStringsW(CommandLine, ExpandedCmdLine, ARRAYSIZE(ExpandedCmdLine)); @@ -194,6 +196,14 @@ StartProcess( si.wShowWindow = SW_SHOWNORMAL; ZeroMemory(&pi, sizeof(pi)); + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + DWORD PathSize = _countof(ProfilePath); + if (GetUserProfileDirectoryW(hToken, ProfilePath, &PathSize)) + WorkingDir = ProfilePath; + CloseHandle(hToken); + } + if (!CreateProcessW(NULL, ExpandedCmdLine, NULL, @@ -201,7 +211,7 @@ StartProcess( FALSE, NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, pEnvironment, - NULL, + WorkingDir, &si, &pi)) {