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.

120 lines
2.6 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <windows.h>
  5. #include <string.h>
  6. #include <direct.h>
  7. #include <errno.h>
  8. #include <sys\types.h>
  9. #include <sys\stat.h>
  10. #include <io.h>
  11. #define UPDATE_INF "UPDATE.INF"
  12. #define SETUP_EXE "SETUP.EXE"
  13. BOOL FFileFound( CHAR *szPath);
  14. int _cdecl
  15. main (INT argc, CHAR ** argv) {
  16. CHAR FileName[MAX_PATH];
  17. CHAR Command[MAX_PATH];
  18. CHAR CommandFormat[] = "%s -i %s -s %s";
  19. CHAR szCWD[MAX_PATH];
  20. CHAR *sz;
  21. STARTUPINFO si;
  22. PROCESS_INFORMATION pi;
  23. BOOL Status;
  24. //
  25. // Determine where this program is run from. Look for update.inf in the
  26. // same directory
  27. //
  28. if (!GetModuleFileName( NULL, FileName, MAX_PATH )) {
  29. printf( "Update.exe: Failed to get the module file name\n" );
  30. exit(1);
  31. }
  32. if ( !( sz = strrchr( FileName, '\\' ) ) ) {
  33. printf( "Update.exe: Module file name not valid\n" );
  34. exit(1);
  35. }
  36. *sz = '\0';
  37. strcpy( szCWD, FileName );
  38. if( lstrlen( szCWD ) == 2 ) {
  39. strcat( szCWD, "\\" );
  40. }
  41. strcat( FileName, "\\");
  42. strcat( FileName, UPDATE_INF );
  43. if (!FFileFound( FileName )) {
  44. printf( "Update.exe: INF %s not found.\n", FileName );
  45. exit(1);
  46. }
  47. sprintf ( Command, CommandFormat, SETUP_EXE, FileName, szCWD );
  48. //
  49. // Run CreateProcess on setup.exe with the update.inf on this source
  50. //
  51. si.cb = sizeof(STARTUPINFO);
  52. si.lpReserved = NULL;
  53. si.lpDesktop = NULL;
  54. si.lpTitle = NULL;
  55. si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  56. si.dwFlags = 0L;
  57. si.wShowWindow = 0;
  58. si.lpReserved2 = NULL;
  59. si.cbReserved2 = 0;
  60. Status = CreateProcess(
  61. NULL,
  62. Command,
  63. NULL,
  64. NULL,
  65. FALSE,
  66. DETACHED_PROCESS,
  67. NULL,
  68. szCWD,
  69. (LPSTARTUPINFO)&si,
  70. (LPPROCESS_INFORMATION)&pi
  71. );
  72. //
  73. // Close the process and thread handles
  74. //
  75. if ( !Status ) {
  76. DWORD dw = GetLastError();
  77. printf( "Update.exe: Failed to run: %s, Error Code: %d\n", Command, dw );
  78. exit(1);
  79. }
  80. CloseHandle( pi.hThread );
  81. CloseHandle( pi.hProcess );
  82. //
  83. // exit
  84. //
  85. exit(0);
  86. return(0);
  87. }
  88. BOOL FFileFound(szPath)
  89. CHAR *szPath;
  90. {
  91. WIN32_FIND_DATA ffd;
  92. HANDLE SearchHandle;
  93. if ( (SearchHandle = FindFirstFile( szPath, &ffd )) == INVALID_HANDLE_VALUE ) {
  94. return( FALSE );
  95. }
  96. else {
  97. FindClose( SearchHandle );
  98. return( TRUE );
  99. }
  100. }