Leaked source code of windows server 2003
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.

110 lines
3.2 KiB

  1. /*---------------------------------------------------------------------------
  2. File: RebootComputer.cpp
  3. Comments: Implementation of COM object to reboot a remote computer.
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 02/15/99 11:21:40
  9. ---------------------------------------------------------------------------
  10. */
  11. // RebootComputer.cpp : Implementation of CRebootComputer
  12. #include "stdafx.h"
  13. #include "WorkObj.h"
  14. #include "Reboot.h"
  15. #include "UString.hpp"
  16. #include "ResStr.h"
  17. //#import "\bin\McsVarSetMin.tlb" no_namespace
  18. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CRebootComputer
  21. #include "BkupRstr.hpp"
  22. STDMETHODIMP
  23. CRebootComputer::Reboot(
  24. BSTR Computer, // in - name of computer to reboot
  25. DWORD delay // in - delay in seconds before rebooting
  26. )
  27. {
  28. HRESULT hr = S_OK;
  29. DWORD rc;
  30. rc = ComputerShutDown((WCHAR*)Computer,NULL,delay,TRUE,m_bNoChange);
  31. if ( rc )
  32. {
  33. hr = HRESULT_FROM_WIN32(rc);
  34. }
  35. return hr;
  36. }
  37. STDMETHODIMP
  38. CRebootComputer::get_NoChange(
  39. BOOL * pVal // out- flag, whether to actually reboot when reboot is called (or to do dry-run)
  40. )
  41. {
  42. (*pVal) = m_bNoChange;
  43. return S_OK;
  44. }
  45. STDMETHODIMP
  46. CRebootComputer::put_NoChange(
  47. BOOL newVal // in - flag, whether to really reboot, or to do a dry run
  48. )
  49. {
  50. m_bNoChange = newVal;
  51. return S_OK;
  52. }
  53. // RebootComputer WorkNode: Reboots a remote computer, with an optional delay
  54. // This function is not currently used by the domain migrator product, but provides
  55. // and alternate way for clients to use this COM object
  56. //
  57. // VarSet Syntax:
  58. // Input:
  59. // RebootComputer.Computer: <ComputerName>
  60. // RebootComputer.Message: <Message> (optional)
  61. // RebootComputer.Delay: <number-of-seconds> (optional, default=0)
  62. // RebootComputer.Restart: <Yes|No> (optional, default=Yes)
  63. STDMETHODIMP
  64. CRebootComputer::Process(
  65. IUnknown * pWorkItem // in - varset containing settings
  66. )
  67. {
  68. HRESULT hr = S_OK;
  69. IVarSetPtr pVarSet = pWorkItem;
  70. DWORD delay = 0;
  71. BOOL restart = TRUE;
  72. _bstr_t computer = pVarSet->get(L"RebootComputer.Computer");
  73. _bstr_t message = pVarSet->get(L"RebootComputer.Message");
  74. _bstr_t text = pVarSet->get(L"RebootComputer.Restart");
  75. if ( !UStrICmp(text,GET_STRING(IDS_No)) )
  76. {
  77. restart = FALSE;
  78. }
  79. delay = (LONG)pVarSet->get(L"RebootComputer.Delay");
  80. if ( computer.length() )
  81. {
  82. DWORD rc = ComputerShutDown((WCHAR*)computer,(WCHAR*)message,delay,restart,FALSE);
  83. if ( rc )
  84. {
  85. hr = HRESULT_FROM_WIN32(rc);
  86. }
  87. }
  88. return hr;
  89. }