Skip to content

Commit 5aea1c7

Browse files
katahiromzJoachimHenze
authored andcommitted
[0.4.11] [SHELL32] Enable environment variables in 'Run' dialog (reactos#1111)
CORE-15431 (1 of 2) cherry picked from commit 0.4.12-dev-19-g 06d717e
1 parent 842671e commit 5aea1c7

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

dll/win32/shell32/dialogs/dialogs.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
551551
LRESULT lRet;
552552
HWND htxt = GetDlgItem(hwnd, IDC_RUNDLG_EDITPATH);
553553
INT ic;
554-
WCHAR *psz, *parent = NULL;
554+
WCHAR *psz, *pszExpanded, *parent = NULL;
555+
DWORD cchExpand;
555556
NMRUNFILEDLGW nmrfd;
556557

557558
ic = GetWindowTextLengthW(htxt);
@@ -575,6 +576,24 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
575576
GetWindowTextW(htxt, psz, ic + 1);
576577
StrTrimW(psz, L" \t");
577578

579+
if (wcschr(psz, L'%') != NULL)
580+
{
581+
cchExpand = ExpandEnvironmentStringsW(psz, NULL, 0);
582+
pszExpanded = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, cchExpand * sizeof(WCHAR));
583+
if (!pszExpanded)
584+
{
585+
HeapFree(GetProcessHeap(), 0, psz);
586+
EndDialog(hwnd, IDCANCEL);
587+
return TRUE;
588+
}
589+
ExpandEnvironmentStringsW(psz, pszExpanded, cchExpand);
590+
StrTrimW(pszExpanded, L" \t");
591+
}
592+
else
593+
{
594+
pszExpanded = psz;
595+
}
596+
578597
/*
579598
* The precedence is the following: first the user-given
580599
* current directory is used; if there is none, a current
@@ -604,7 +623,7 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
604623
nmrfd.hdr.code = RFN_VALIDATE;
605624
nmrfd.hdr.hwndFrom = hwnd;
606625
nmrfd.hdr.idFrom = 0;
607-
nmrfd.lpFile = psz;
626+
nmrfd.lpFile = pszExpanded;
608627
nmrfd.lpDirectory = pszStartDir;
609628
nmrfd.nShow = SW_SHOWNORMAL;
610629

@@ -617,12 +636,12 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
617636
break;
618637

619638
case RF_OK:
620-
if (SUCCEEDED(ShellExecCmdLine(hwnd, psz, pszStartDir, SW_SHOWNORMAL, NULL,
639+
if (SUCCEEDED(ShellExecCmdLine(hwnd, pszExpanded, pszStartDir, SW_SHOWNORMAL, NULL,
621640
SECL_ALLOW_NONEXE)))
622641
{
623642
/* Call again GetWindowText in case the contents of the edit box has changed? */
624-
GetWindowTextW(htxt, psz, ic + 1);
625-
FillList(htxt, psz, ic + 2 + 1, FALSE);
643+
GetWindowTextW(htxt, pszExpanded, ic + 1);
644+
FillList(htxt, pszExpanded, ic + 2 + 1, FALSE);
626645
EndDialog(hwnd, IDOK);
627646
break;
628647
}
@@ -638,6 +657,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
638657

639658
HeapFree(GetProcessHeap(), 0, parent);
640659
HeapFree(GetProcessHeap(), 0, psz);
660+
if (psz != pszExpanded)
661+
HeapFree(GetProcessHeap(), 0, pszExpanded);
641662
return TRUE;
642663
}
643664

0 commit comments

Comments
 (0)