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.

76 lines
2.3 KiB

  1. #include <windows.h>
  2. #include <shellapi.h>
  3. //+----------------------------------------------------------------------------
  4. //
  5. // Function: ExtractCmBinsFromExe
  6. //
  7. // Synopsis: Launches cmbins.exe to extract the cm binaries from the executable
  8. // cab file.
  9. //
  10. // Arguments: LPTSTR pszPathToExtractFrom -- path where cmbins.exe lives
  11. // LPTSTR pszPathToExtractTo -- path to where cm binaries are extracted to
  12. //
  13. // Returns: HRESULT - standard COM error codes
  14. //
  15. // History: quintinb Created 03/14/2001
  16. //
  17. //+----------------------------------------------------------------------------
  18. HRESULT ExtractCmBinsFromExe(LPTSTR pszPathToExtractFrom, LPTSTR pszPathToExtractTo)
  19. {
  20. HRESULT hr = E_INVALIDARG;
  21. if (pszPathToExtractTo && (TEXT('\0') != pszPathToExtractTo[0]) &&
  22. pszPathToExtractFrom && (TEXT('\0') != pszPathToExtractFrom[0]))
  23. {
  24. TCHAR szFile[MAX_PATH+1] = {0};
  25. TCHAR szParams[MAX_PATH+1] = {0};
  26. LPCTSTR c_pszParamsFmt = TEXT("/c /q /t:%s");
  27. LPCTSTR c_pszFileFmt = TEXT("%scmbins.exe");
  28. LPCTSTR c_pszFileFmtWithSlash = TEXT("%s\\cmbins.exe");
  29. wsprintf(szParams, c_pszParamsFmt, pszPathToExtractTo);
  30. if (TEXT('\\') == pszPathToExtractFrom[lstrlen(pszPathToExtractFrom) - 1])
  31. {
  32. wsprintf(szFile, c_pszFileFmt, pszPathToExtractFrom);
  33. }
  34. else
  35. {
  36. wsprintf(szFile, c_pszFileFmtWithSlash, pszPathToExtractFrom);
  37. }
  38. SHELLEXECUTEINFO sei = {0};
  39. sei.cbSize = sizeof(sei);
  40. sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
  41. sei.nShow = SW_SHOWNORMAL;
  42. sei.lpFile = szFile;
  43. sei.lpParameters = szParams;
  44. sei.lpDirectory = pszPathToExtractFrom;
  45. if (ShellExecuteEx(&sei))
  46. {
  47. if (sei.hProcess)
  48. {
  49. WaitForSingleObject(sei.hProcess, 1000*60*1); // wait for one minute.
  50. CloseHandle(sei.hProcess);
  51. }
  52. hr = S_OK;
  53. }
  54. else
  55. {
  56. hr = HRESULT_FROM_WIN32(GetLastError());
  57. //
  58. // Make sure to return failure
  59. //
  60. if (SUCCEEDED(hr))
  61. {
  62. hr = E_UNEXPECTED;
  63. }
  64. }
  65. }
  66. return hr;
  67. }