Source code of Windows XP (NT5)
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.

87 lines
2.4 KiB

  1. // PropShellExt.cpp : Implementation of CW3extApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "w3ext.h"
  4. #include "PropShellExt.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. // IShellExtInit Implementation.
  8. STDMETHODIMP
  9. CPropShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID)
  10. {
  11. if (pDataObj == NULL)
  12. {
  13. ATLASSERT(FALSE);
  14. return (E_INVALIDARG);
  15. }
  16. FORMATETC f = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  17. STGMEDIUM m;
  18. HRESULT hr = pDataObj->GetData(&f, &m);
  19. if (FAILED(hr))
  20. {
  21. return(hr);
  22. }
  23. if (1 == DragQueryFile((HDROP)m.hGlobal, (UINT)(-1), NULL,0))
  24. {
  25. TCHAR szFileName[MAX_PATH];
  26. DragQueryFile((HDROP)m.hGlobal, 0, szFileName, sizeof(szFileName));
  27. SHFILEINFO shfi;
  28. SHGetFileInfo(szFileName, 0, &shfi, sizeof(SHFILEINFO), SHGFI_ATTRIBUTES);
  29. if ( (shfi.dwAttributes & (SFGAO_LINK | SFGAO_REMOVABLE)) == 0
  30. && (shfi.dwAttributes & SFGAO_FILESYSTEM) != 0
  31. )
  32. {
  33. int drive_number, drive_type;
  34. TCHAR szRoot[4];
  35. if ( -1 != (drive_number = PathGetDriveNumber(szFileName))
  36. && NULL != PathBuildRoot(szRoot, drive_number)
  37. && DRIVE_REMOTE != (drive_type = GetDriveType(szRoot))
  38. && DRIVE_NO_ROOT_DIR != drive_type
  39. )
  40. {
  41. StrCpy(m_szFileName, szFileName);
  42. }
  43. }
  44. }
  45. ReleaseStgMedium(&m);
  46. return hr;
  47. }
  48. STDMETHODIMP
  49. CPropShellExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  50. {
  51. // We only add the page if the user has admin priviliges in the metabase.
  52. // The only way to check it now is to try to write something.
  53. // Test key is /LM/W3SVC.
  54. CMetabasePath path(SZ_MBN_WEB);
  55. CMetaKey key(LOCAL_KEY, path,
  56. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE
  57. );
  58. if (key.Succeeded() && SUCCEEDED(key.SetValue(MD_ISM_ACCESS_CHECK, 0x0000FFFF)))
  59. {
  60. m_psW3ShellExtProp.SetParentExt(this);
  61. HPROPSHEETPAGE hpage = m_psW3ShellExtProp.Create();
  62. ASSERT(hpage != NULL);
  63. if (NULL != hpage)
  64. {
  65. AddRef();
  66. if (!lpfnAddPage(hpage, lParam))
  67. {
  68. DestroyPropertySheetPage(hpage);
  69. }
  70. }
  71. }
  72. return key.QueryResult();
  73. }
  74. STDMETHODIMP
  75. CPropShellExt::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  76. {
  77. return E_FAIL;
  78. }