Skip to content

Commit 37574d1

Browse files
authored
[TASKMGR] Open the Command Prompt when holding CTRL while clicking "New Task" (reactos#8459)
This is a useful feature that also exists in Windows' own Task Manager.
1 parent a3147ab commit 37574d1

File tree

1 file changed

+43
-0
lines changed
  • base/applications/taskmgr

1 file changed

+43
-0
lines changed

base/applications/taskmgr/run.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,49 @@ void TaskManager_OnFileNew(void)
1515
WCHAR szTitle[40];
1616
WCHAR szText[256];
1717

18+
/* If CTRL is held, start the user's command-line shell */
19+
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
20+
{
21+
STARTUPINFOW si = { sizeof(si) };
22+
PROCESS_INFORMATION pi;
23+
WCHAR szComSpec[MAX_PATH];
24+
WCHAR fallbackCmd[] = L"cmd.exe";
25+
DWORD cchEnv = GetEnvironmentVariableW(L"ComSpec", szComSpec, _countof(szComSpec));
26+
if (cchEnv == 0 || cchEnv > _countof(szComSpec))
27+
{
28+
/* Couldn't get the environment variable, default to cmd.exe */
29+
wcscpy(szComSpec, fallbackCmd);
30+
}
31+
BOOL result = CreateProcessW(NULL,
32+
szComSpec,
33+
NULL,
34+
NULL,
35+
FALSE,
36+
CREATE_NEW_CONSOLE,
37+
NULL,
38+
NULL,
39+
&si, &pi);
40+
if (!result)
41+
{
42+
/* Couldn't start the user's command-line shell, fall back to cmd.exe */
43+
result = CreateProcessW(NULL,
44+
fallbackCmd,
45+
NULL,
46+
NULL,
47+
FALSE,
48+
CREATE_NEW_CONSOLE,
49+
NULL,
50+
NULL,
51+
&si, &pi);
52+
}
53+
if (result)
54+
{
55+
CloseHandle(pi.hThread);
56+
CloseHandle(pi.hProcess);
57+
}
58+
return;
59+
}
60+
1861
/* Load language strings from resource file */
1962
LoadStringW(hInst, IDS_CREATENEWTASK, szTitle, _countof(szTitle));
2063
LoadStringW(hInst, IDS_CREATENEWTASK_DESC, szText, _countof(szText));

0 commit comments

Comments
 (0)