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.

106 lines
3.4 KiB

  1. // ProfMig.cpp : Implementation of CExtendProfileMigration
  2. #include "stdafx.h"
  3. #import "\bin\McsVarSetMin.tlb" no_namespace
  4. #include "ProfExt.h"
  5. #include "ProfMig.h"
  6. #include "TReg.hpp"
  7. #include "ErrDct.hpp"
  8. #define LEN_Path 255
  9. TErrorDct err;
  10. TError& errCommon = err;
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CExtendProfileMigration
  13. STDMETHODIMP CExtendProfileMigration::GetRequiredFiles(SAFEARRAY **pArray)
  14. {
  15. SAFEARRAYBOUND bound[1] = { 1, 0 };
  16. LONG ndx[1] = { 0 };
  17. (*pArray) = SafeArrayCreate(VT_BSTR,1,bound);
  18. SafeArrayPutElement(*pArray,ndx,SysAllocString(L"ProfExt.DLL"));
  19. return S_OK;
  20. }
  21. STDMETHODIMP CExtendProfileMigration::GetRegisterableFiles(SAFEARRAY **pArray)
  22. {
  23. SAFEARRAYBOUND bound[1] = { 1, 0 };
  24. LONG ndx[1] = { 0 };
  25. (*pArray) = SafeArrayCreate(VT_BSTR,1,bound);
  26. SafeArrayPutElement(*pArray,ndx,SysAllocString(L"ProfExt.DLL"));
  27. return S_OK;
  28. }
  29. STDMETHODIMP CExtendProfileMigration::UpdateProfile(IUnknown *pVarSet)
  30. {
  31. HRESULT hr = S_OK;
  32. _variant_t varSourceSam;
  33. _variant_t varSourceDom;
  34. _variant_t varRegKey;
  35. IVarSetPtr pVs = pVarSet;
  36. varSourceSam = pVs->get(L"Account.SourceSam");
  37. varSourceDom = pVs->get(L"SourceDomain");
  38. varRegKey = pVs->get(L"Profile.RegKey");
  39. hr = UpdateMappedDrives( V_BSTR(&varSourceSam), V_BSTR(&varSourceDom), V_BSTR(&varRegKey) );
  40. return hr;
  41. }
  42. // UpdateMappedDrives : This function looks in the Network key to find all the mapped drives and for the drives that have
  43. // sourceDomain\sourceAccount as the user account we set it to "".
  44. HRESULT CExtendProfileMigration::UpdateMappedDrives(BSTR sSourceSam, BSTR sSourceDomain, BSTR sRegistryKey)
  45. {
  46. TRegKey reg;
  47. TRegKey regDrive;
  48. DWORD rc = 0;
  49. WCHAR netKey[LEN_Path];
  50. int len = LEN_Path;
  51. int ndx = 0;
  52. HRESULT hr = S_OK;
  53. WCHAR sValue[LEN_Path];
  54. WCHAR sAcct[LEN_Path];
  55. WCHAR keyname[LEN_Path];
  56. // Build the account name string that we need to check for
  57. wsprintf(sAcct, L"%s\\%s", (WCHAR*) sSourceDomain, (WCHAR*) sSourceSam);
  58. // Get the path to the Network subkey for this users profile.
  59. wsprintf(netKey, L"%s\\%s", (WCHAR*) sRegistryKey, L"Network");
  60. rc = reg.Open(netKey, HKEY_USERS);
  61. if ( !rc )
  62. {
  63. while ( !reg.SubKeyEnum(ndx, keyname, len) )
  64. {
  65. rc = regDrive.Open(keyname, reg.KeyGet());
  66. if ( !rc )
  67. {
  68. // Get the user name value that we need to check.
  69. rc = regDrive.ValueGetStr(L"UserName", sValue, LEN_Path);
  70. if ( !rc )
  71. {
  72. if ( !wcsicmp(sAcct, sValue) )
  73. {
  74. // Found this account name in the mapped drive user name.so we will set the key to ""
  75. regDrive.ValueSetStr(L"UserName", L"");
  76. }
  77. }
  78. else
  79. hr = HRESULT_FROM_WIN32(GetLastError());
  80. }
  81. else
  82. hr = HRESULT_FROM_WIN32(GetLastError());
  83. ndx++;
  84. }
  85. reg.Close();
  86. }
  87. else
  88. hr = HRESULT_FROM_WIN32(GetLastError());
  89. return hr;
  90. }