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.

162 lines
3.3 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include "rc_ids.h"
  4. //
  5. // This app is a very simple wrapper for autoplay functionality
  6. // for x86. It invokes winnt.exe on Win95 and winnt32.exe on NT.
  7. //
  8. #define SUCCESS 0
  9. #define FAILURE 1
  10. VOID
  11. Error(
  12. IN UINT Id,
  13. IN PCSTR Parameter OPTIONAL
  14. )
  15. {
  16. CHAR String[1024];
  17. CHAR Message[4096];
  18. LoadString(
  19. GetModuleHandle(NULL),
  20. Id,
  21. String,
  22. sizeof(String)
  23. );
  24. if(Parameter) {
  25. _snprintf(Message,sizeof(Message),String,Parameter);
  26. } else {
  27. lstrcpy(Message,String);
  28. }
  29. MessageBox(NULL,Message,NULL,MB_ICONERROR|MB_OK|MB_SYSTEMMODAL);
  30. }
  31. int
  32. __cdecl
  33. main(
  34. VOID
  35. )
  36. {
  37. PCSTR CmdLine;
  38. CHAR cmdLine[4096];
  39. PCSTR CmdLineTail;
  40. unsigned TailOffset;
  41. CHAR ModuleName[MAX_PATH];
  42. PCHAR p;
  43. OSVERSIONINFO VersionInfo;
  44. BOOL b;
  45. STARTUPINFO StartupInfo;
  46. PROCESS_INFORMATION ProcessInfo;
  47. //
  48. // Form name of app we want to invoke.
  49. //
  50. GetModuleFileName(GetModuleHandle(NULL),ModuleName,MAX_PATH);
  51. CharUpper(ModuleName);
  52. p = strstr(ModuleName,"\\_WINNT.EXE");
  53. if(!p) {
  54. Error(INVALID_MODNAME,ModuleName);
  55. return(FAILURE);
  56. }
  57. *(++p) = 0;
  58. VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  59. if(!GetVersionEx(&VersionInfo)) {
  60. Error(GETVER_FAILED,NULL);
  61. return(FAILURE);
  62. }
  63. lstrcpy(
  64. p,
  65. (VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? "WINNT32.EXE" : "WINNT.EXE"
  66. );
  67. //
  68. // Get the command line. We will assume that this app is in
  69. // some subdirectory, probably \i386, on the CD, and that it is
  70. // called _winnt.exe.
  71. //
  72. CmdLine = GetCommandLine();
  73. //
  74. // Uppercase the command line so we can locate the command tail.
  75. //
  76. lstrcpyn(cmdLine,CmdLine,sizeof(cmdLine));
  77. CharUpper(cmdLine);
  78. CmdLineTail = strstr(cmdLine,"\\_WINNT");
  79. if(CmdLineTail == NULL) {
  80. Error(INVALID_CMDLINE,CmdLine);
  81. return(FAILURE);
  82. }
  83. CmdLineTail += sizeof("\\_WINNT") - 1;
  84. if(*CmdLineTail == '\"') {
  85. CmdLineTail++;
  86. } else {
  87. //
  88. // The next characters better be .exe or a space.
  89. //
  90. if(strncmp(CmdLineTail," ",1) && strncmp(CmdLineTail,".EXE ",5)) {
  91. Error(INVALID_CMDLINE,CmdLine);
  92. return(FAILURE);
  93. }
  94. }
  95. CmdLineTail = strchr(CmdLineTail,' ');
  96. if(!CmdLineTail) {
  97. CmdLineTail += lstrlen(CmdLineTail);
  98. }
  99. //
  100. // Now we want to point to the non-lowercased cmd line tail
  101. //
  102. TailOffset = CmdLineTail - cmdLine;
  103. CmdLineTail = CmdLine + TailOffset;
  104. //
  105. // Build a full command line: appname + cmd tail
  106. //
  107. lstrcpy(cmdLine,ModuleName);
  108. lstrcat(cmdLine,CmdLineTail);
  109. //
  110. // Invoke the correct setup app.
  111. //
  112. ZeroMemory(&StartupInfo,sizeof(STARTUPINFO));
  113. StartupInfo.cb = sizeof(STARTUPINFO);
  114. b = CreateProcess(
  115. ModuleName,
  116. cmdLine,
  117. NULL,
  118. NULL,
  119. FALSE,
  120. 0,
  121. NULL,
  122. NULL,
  123. &StartupInfo,
  124. &ProcessInfo
  125. );
  126. if(!b) {
  127. Error(CREATEPROC_FAILED,cmdLine);
  128. return(FAILURE);
  129. }
  130. CloseHandle(ProcessInfo.hThread);
  131. CloseHandle(ProcessInfo.hProcess);
  132. return(SUCCESS);
  133. }