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.

88 lines
2.1 KiB

  1. // ChangeDomTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "driver.h"
  5. #include "ChgDom.h"
  6. #import "\bin\McsDctWorkerObjects.tlb" no_namespace, named_guids
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CChangeDomTestDlg property page
  14. IMPLEMENT_DYNCREATE(CChangeDomTestDlg, CPropertyPage)
  15. CChangeDomTestDlg::CChangeDomTestDlg() : CPropertyPage(CChangeDomTestDlg::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CChangeDomTestDlg)
  18. m_Computer = _T("");
  19. m_Domain = _T("");
  20. m_NoChange = FALSE;
  21. //}}AFX_DATA_INIT
  22. }
  23. CChangeDomTestDlg::~CChangeDomTestDlg()
  24. {
  25. }
  26. void CChangeDomTestDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CPropertyPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CChangeDomTestDlg)
  30. DDX_Text(pDX, IDC_COMPUTER, m_Computer);
  31. DDX_Text(pDX, IDC_DOMAIN, m_Domain);
  32. DDX_Check(pDX, IDC_NOCHANGE, m_NoChange);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CChangeDomTestDlg, CPropertyPage)
  36. //{{AFX_MSG_MAP(CChangeDomTestDlg)
  37. ON_BN_CLICKED(IDC_CHANGE_DOMAIN, OnChangeDomain)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CChangeDomTestDlg message handlers
  42. void CChangeDomTestDlg::OnChangeDomain()
  43. {
  44. UpdateData(TRUE);
  45. CWaitCursor w;
  46. IChangeDomainPtr pCDom;
  47. CString msg;
  48. HRESULT hr;
  49. hr = pCDom.CreateInstance(CLSID_ChangeDomain);
  50. if ( FAILED(hr) )
  51. {
  52. msg.Format(L"Failed to create ChangeDomain COM object, CoCreateInstance returned %lx",hr);
  53. }
  54. else
  55. {
  56. pCDom->NoChange = m_NoChange;
  57. BSTR status = NULL;
  58. hr = pCDom->raw_ChangeToWorkgroup(m_Computer.AllocSysString(),SysAllocString(L"WORKGROUP"),&status);
  59. if ( SUCCEEDED(hr) )
  60. {
  61. hr = pCDom->raw_ChangeToDomain(m_Computer.AllocSysString(),m_Domain.AllocSysString(),m_Computer.AllocSysString(),&status);
  62. }
  63. if ( SUCCEEDED(hr) )
  64. {
  65. msg = L"ChangeDomain succeeded!";
  66. }
  67. else
  68. {
  69. msg.Format(L"ChangeDomain failed, %ls, hr=%lx",(WCHAR*)status,hr);
  70. }
  71. }
  72. MessageBox(msg);
  73. }