@@ -551,7 +551,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
551
551
LRESULT lRet;
552
552
HWND htxt = GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH);
553
553
INT ic;
554
- WCHAR *psz, *parent = NULL ;
554
+ WCHAR *psz, *pszExpanded, *parent = NULL ;
555
+ DWORD cchExpand;
555
556
NMRUNFILEDLGW nmrfd;
556
557
557
558
ic = GetWindowTextLengthW (htxt);
@@ -575,6 +576,24 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
575
576
GetWindowTextW (htxt, psz, ic + 1 );
576
577
StrTrimW (psz, L" \t " );
577
578
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
+
578
597
/*
579
598
* The precedence is the following: first the user-given
580
599
* 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
604
623
nmrfd.hdr .code = RFN_VALIDATE;
605
624
nmrfd.hdr .hwndFrom = hwnd;
606
625
nmrfd.hdr .idFrom = 0 ;
607
- nmrfd.lpFile = psz ;
626
+ nmrfd.lpFile = pszExpanded ;
608
627
nmrfd.lpDirectory = pszStartDir;
609
628
nmrfd.nShow = SW_SHOWNORMAL;
610
629
@@ -617,12 +636,12 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
617
636
break ;
618
637
619
638
case RF_OK:
620
- if (SUCCEEDED (ShellExecCmdLine (hwnd, psz , pszStartDir, SW_SHOWNORMAL, NULL ,
639
+ if (SUCCEEDED (ShellExecCmdLine (hwnd, pszExpanded , pszStartDir, SW_SHOWNORMAL, NULL ,
621
640
SECL_ALLOW_NONEXE)))
622
641
{
623
642
/* 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 );
626
645
EndDialog (hwnd, IDOK);
627
646
break ;
628
647
}
@@ -638,6 +657,8 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
638
657
639
658
HeapFree (GetProcessHeap (), 0 , parent);
640
659
HeapFree (GetProcessHeap (), 0 , psz);
660
+ if (psz != pszExpanded)
661
+ HeapFree (GetProcessHeap (), 0 , pszExpanded);
641
662
return TRUE ;
642
663
}
643
664
0 commit comments