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.

82 lines
1.9 KiB

  1. // RebootTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Driver.h"
  5. #include "Reboot.h"
  6. #import "\bin\McsDctWorkerObjects.tlb" no_namespace, named_guids
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CRebootTestDlg property page
  9. IMPLEMENT_DYNCREATE(CRebootTestDlg, CPropertyPage)
  10. CRebootTestDlg::CRebootTestDlg() : CPropertyPage(CRebootTestDlg::IDD)
  11. {
  12. //{{AFX_DATA_INIT(CRebootTestDlg)
  13. m_Computer = _T("");
  14. m_Delay = 0;
  15. m_NoChange = FALSE;
  16. //}}AFX_DATA_INIT
  17. }
  18. CRebootTestDlg::~CRebootTestDlg()
  19. {
  20. }
  21. void CRebootTestDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CPropertyPage::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CRebootTestDlg)
  25. DDX_Text(pDX, IDC_COMPUTER, m_Computer);
  26. DDX_Text(pDX, IDC_Delay, m_Delay);
  27. DDX_Check(pDX, IDC_NOCHANGE, m_NoChange);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CRebootTestDlg, CPropertyPage)
  31. //{{AFX_MSG_MAP(CRebootTestDlg)
  32. ON_BN_CLICKED(IDC_REBOOT, OnReboot)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CRebootTestDlg message handlers
  37. void CRebootTestDlg::OnReboot()
  38. {
  39. UpdateData(TRUE);
  40. CWaitCursor w;
  41. IRebootComputerPtr pReboot;
  42. CString msg;
  43. HRESULT hr;
  44. if ( ! m_NoChange && m_Computer.IsEmpty() )
  45. {
  46. if ( IDNO == MessageBox(L"Are you sure you want to reboot the local machine now?",NULL,MB_YESNO) )
  47. return;
  48. }
  49. hr = pReboot.CreateInstance(CLSID_RebootComputer);
  50. if ( FAILED(hr) )
  51. {
  52. msg.Format(L"Failed to create Reboot COM object, CoCreateInstance returned %lx",hr);
  53. }
  54. else
  55. {
  56. pReboot->NoChange = m_NoChange;
  57. hr = pReboot->raw_Reboot(m_Computer.AllocSysString(),m_Delay);
  58. if ( SUCCEEDED(hr) )
  59. {
  60. msg = L"Reboot succeeded!";
  61. }
  62. else
  63. {
  64. msg.Format(L"Reboot failed, hr=%lx",hr);
  65. }
  66. }
  67. MessageBox(msg);
  68. }