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.

117 lines
2.8 KiB

  1. // CompPwdAgeTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Driver.h"
  5. #include "PwdAge.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. // CCompPwdAgeTestDlg property page
  14. IMPLEMENT_DYNCREATE(CCompPwdAgeTestDlg, CPropertyPage)
  15. CCompPwdAgeTestDlg::CCompPwdAgeTestDlg() : CPropertyPage(CCompPwdAgeTestDlg::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CCompPwdAgeTestDlg)
  18. m_Computer = _T("");
  19. m_Domain = _T("");
  20. m_Filename = _T("C:\\CompPwdAge.txt");
  21. //}}AFX_DATA_INIT
  22. }
  23. CCompPwdAgeTestDlg::~CCompPwdAgeTestDlg()
  24. {
  25. }
  26. void CCompPwdAgeTestDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CPropertyPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CCompPwdAgeTestDlg)
  30. DDX_Text(pDX, IDC_COMPUTER, m_Computer);
  31. DDX_Text(pDX, IDC_DOMAIN, m_Domain);
  32. DDX_Text(pDX, IDC_FILENAME, m_Filename);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CCompPwdAgeTestDlg, CPropertyPage)
  36. //{{AFX_MSG_MAP(CCompPwdAgeTestDlg)
  37. ON_BN_CLICKED(IDC_EXPORT, OnExport)
  38. ON_BN_CLICKED(IDC_GET_PWD_AGE, OnGetPwdAge)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CCompPwdAgeTestDlg message handlers
  43. void CCompPwdAgeTestDlg::OnExport()
  44. {
  45. UpdateData(TRUE);
  46. CWaitCursor w;
  47. IComputerPwdAgePtr pPwdAge;
  48. HRESULT hr = pPwdAge.CreateInstance(CLSID_ComputerPwdAge);
  49. if ( FAILED(hr) )
  50. {
  51. CString msg;
  52. msg.Format(L"Failed to create ComputerPwdAge COM object, CoCreateInstance returned %lx",hr);
  53. MessageBox(msg);
  54. }
  55. else
  56. {
  57. hr = pPwdAge->raw_ExportPasswordAge(m_Domain.AllocSysString(),m_Filename.AllocSysString());
  58. if ( SUCCEEDED(hr) )
  59. {
  60. MessageBox(L"Succeeded!");
  61. }
  62. else
  63. {
  64. CString msg;
  65. msg.Format(L"Export failed, hr=%lx",hr);
  66. MessageBox(msg);
  67. }
  68. }
  69. }
  70. void CCompPwdAgeTestDlg::OnGetPwdAge()
  71. {
  72. UpdateData(TRUE);
  73. CWaitCursor w;
  74. IComputerPwdAgePtr pPwdAge;
  75. HRESULT hr = pPwdAge.CreateInstance(CLSID_ComputerPwdAge);
  76. if ( FAILED(hr) )
  77. {
  78. CString msg;
  79. msg.Format(L"Failed to create ComputerPwdAge COM object, CoCreateInstance returned %lx",hr);
  80. MessageBox(msg);
  81. }
  82. else
  83. {
  84. DWORD age;
  85. hr = pPwdAge->raw_GetPwdAge(m_Domain.AllocSysString(),m_Computer.AllocSysString(),&age);
  86. CString msg;
  87. if ( SUCCEEDED(hr) )
  88. {
  89. msg.Format(L"The password age is %ld seconds (%ld days).",age,age / (60*60*24) );
  90. }
  91. else
  92. {
  93. msg.Format(L"GetPwdAge failed, hr=%lx",hr);
  94. }
  95. MessageBox(msg);
  96. }
  97. }