Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. BOOL _CopyCommand(LPCTSTR pszCommand, LPCTSTR pszDir, LPTSTR pszOut, DWORD cchOut)
  4. {
  5. BOOL fCopyBack = TRUE;
  6. BOOL fRet = TRUE;
  7. // if it does not have quotes, try unquoted name to see if that works...
  8. if (pszCommand[0] != TEXT('"'))
  9. {
  10. if (UrlIs(pszCommand, URLIS_URL))
  11. {
  12. // urls never have params...
  13. fCopyBack = fRet = FALSE;
  14. lstrcpyn(pszOut, pszCommand, cchOut);
  15. }
  16. else if (StrChr(pszCommand, TEXT(' ')))
  17. {
  18. lstrcpyn(pszOut, pszCommand, cchOut);
  19. PathQualifyDef(pszOut, pszDir, 0);
  20. // Check for possible existence of arguments
  21. if (PathFileExistsAndAttributes(pszOut, NULL))
  22. {
  23. fCopyBack = fRet = FALSE;
  24. }
  25. }
  26. else
  27. fRet = FALSE;
  28. }
  29. // we need to put the original command for args parsing
  30. if (fCopyBack)
  31. lstrcpyn(pszOut, pszCommand, cchOut);
  32. return fRet;
  33. }
  34. BOOL _QualifyWorkingDir(LPCTSTR pszPath, LPTSTR pszDir, DWORD cchDir)
  35. {
  36. // special case to make sure the working dir gets set right:
  37. // 1) no working dir specified
  38. // 2) a drive or a root path, or a relative path specified
  39. // derive the working dir from the qualified path. this is to make
  40. // sure the working dir for setup programs "A:setup" is set right
  41. if (StrChr(pszPath, TEXT('\\')) || StrChr(pszPath, TEXT(':')))
  42. {
  43. // build working dir based on qualified path
  44. lstrcpyn(pszDir, pszPath, cchDir);
  45. PathQualifyDef(pszDir, NULL, PQD_NOSTRIPDOTS);
  46. PathRemoveFileSpec(pszDir);
  47. return TRUE;
  48. }
  49. return FALSE;
  50. }
  51. // Run the thing, return TRUE if everything went OK
  52. BOOL ShellExecCmdLine(HWND hwnd, LPCTSTR pszCommand, LPCTSTR pszDir,
  53. int nShow, LPCTSTR pszTitle, DWORD dwFlags)
  54. {
  55. TCHAR szWD[MAX_PATH];
  56. TCHAR szFileName[MAX_PATH];
  57. LPTSTR pszArgs;
  58. SHELLEXECUTEINFO ei = {0};
  59. if (pszDir && *pszDir == TEXT('\0'))
  60. pszDir = NULL;
  61. if (_CopyCommand(pszCommand, pszDir, szFileName, SIZECHARS(szFileName)))
  62. {
  63. // there might be args in that command
  64. pszArgs = PathGetArgs(szFileName);
  65. if (*pszArgs)
  66. *(pszArgs - 1) = TEXT('\0');
  67. }
  68. else
  69. pszArgs = NULL;
  70. PathUnquoteSpaces(szFileName);
  71. // this needs to be here. app installs rely on the current directory
  72. // to be the directory with the setup.exe
  73. if (!UrlIs(szFileName, URLIS_URL)
  74. && ((dwFlags & SECL_USEFULLPATHDIR) || !pszDir))
  75. {
  76. if (_QualifyWorkingDir(szFileName, szWD, SIZECHARS(szWD)))
  77. pszDir = szWD;
  78. }
  79. FillExecInfo(ei, hwnd, NULL, szFileName, pszArgs, pszDir, nShow);
  80. ei.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_DOENVSUBST;
  81. if (dwFlags & SECL_NO_UI)
  82. ei.fMask |= SEE_MASK_FLAG_NO_UI;
  83. if (dwFlags & SECL_SEPARATE_VDM)
  84. ei.fMask |= SEE_MASK_FLAG_SEPVDM;
  85. if (dwFlags & SECL_LOG_USAGE)
  86. ei.fMask |= SEE_MASK_FLAG_LOG_USAGE;
  87. return ShellExecuteEx(&ei);
  88. }