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.

111 lines
2.9 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // RunDll.cpp
  6. //
  7. // Purpose: Allow framework to be used to run a command
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include "multiplat.h"
  12. // This routine is meant to be called from RUNDLL32.EXE
  13. extern "C" {
  14. __declspec(dllexport) VOID CALLBACK
  15. DoCmd(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
  16. {
  17. DWORD dwRet = ERROR_INVALID_FUNCTION;
  18. BOOL bRet = FALSE;
  19. DWORD dwFlags = 0L ;
  20. DWORD dwReserved = 0L ;
  21. CHString CmdLine ( lpszCmdLine ) ;
  22. CHString Buff ;
  23. CHString Args ;
  24. // Parse the passed in command line to figure out what command we
  25. // are being asked to run.
  26. DWORD dwIndex = CmdLine.Find ( L" " ) ;
  27. Buff = CmdLine.Left ( dwIndex ) ;
  28. Args = CmdLine.Mid ( dwIndex + 1 ) ;
  29. CHString sFlags ;
  30. CHString sReserved ;
  31. // Parse out the parameters for this command
  32. dwIndex = Args.Find ( L" " ) ;
  33. if ( dwIndex )
  34. {
  35. sFlags = Args.Left ( dwIndex ) ;
  36. sReserved = Args.Mid ( dwIndex + 1 ) ;
  37. }
  38. else
  39. {
  40. sFlags = Args ;
  41. }
  42. dwFlags = _wtoi ( sFlags ) ;
  43. dwReserved = _wtoi ( sReserved ) ;
  44. // Find out which command
  45. if ( Buff.CompareNoCase ( L"ExitWindowsEx" ) == 0 )
  46. {
  47. // Clear the error (it appears ExitWindowsEx doesn't always clear old data)
  48. SetLastError(0);
  49. bRet = ExitWindowsEx(dwFlags, dwReserved);
  50. dwRet = GetLastError();
  51. }
  52. else if ( Buff.CompareNoCase ( L"InitiateSystemShutdown" ) == 0 )
  53. {
  54. // Parse out the parameters for this command
  55. bool bRebootAfterShutdown = false;
  56. bool bForceShutDown = false;
  57. // Clear the error (it appears ExitWindowsEx doesn't always clear old data)
  58. SetLastError(0);
  59. if(dwFlags & EWX_REBOOT)
  60. {
  61. bRebootAfterShutdown = true;
  62. }
  63. if( dwFlags & EWX_FORCE)
  64. {
  65. bForceShutDown = true;
  66. }
  67. WCHAR wstrComputerName[MAX_COMPUTERNAME_LENGTH + 1] = { '\0' };
  68. DWORD dwSize;
  69. if(FRGetComputerName(wstrComputerName, &dwSize))
  70. {
  71. bRet = InitiateSystemShutdown(
  72. wstrComputerName,
  73. NULL,
  74. 0 /* dwTimeout */,
  75. (bForceShutDown)? TRUE:FALSE,
  76. (bRebootAfterShutdown)? TRUE:FALSE );
  77. dwRet = GetLastError();
  78. }
  79. else
  80. {
  81. dwRet = GetLastError();
  82. }
  83. }
  84. // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  85. //
  86. // We are aborting out at this point, since RunDLL32 in its finite wisdom doesn't allow
  87. // for the setting of the dos error level (who designs this stuff?).
  88. if (!bRet)
  89. {
  90. ExitProcess(dwRet);
  91. }
  92. }
  93. } //extern