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.

42 lines
1.1 KiB

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. int main(int argc, char* argv[])
  6. {
  7. CHAR buff[256];
  8. CHAR FileName[256];
  9. SYSTEMTIME st;
  10. HANDLE hFile;
  11. if( argc == 1 )
  12. {
  13. printf("\nNeed command line arg for destination of env.bat\n");
  14. return 1; // error
  15. }
  16. GetLocalTime( &st );
  17. int YearNumber = st.wYear - 1999;
  18. if( YearNumber < 0 )
  19. {
  20. printf("Invalid year %d - please validate system time.\n", st.wYear);
  21. return 1;
  22. }
  23. st.wYear %= 100;
  24. sprintf( buff,"set build_date=%02d%02d%02d\nset BUILDNO=%02d%02d",
  25. st.wYear, st.wMonth, st.wDay, st.wMonth + YearNumber*12, st.wDay );
  26. strcpy( FileName, argv[1] );
  27. // DWORD dwSize = GetEnvironmentVariable( _T("_NTROOT"),FileName,256);
  28. strcat( FileName, _T("\\env.bat") );
  29. hFile = CreateFile( FileName, GENERIC_READ | GENERIC_WRITE,
  30. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  31. if( hFile != INVALID_HANDLE_VALUE )
  32. {
  33. DWORD dw;
  34. WriteFile( hFile, buff, strlen(buff), &dw, NULL );
  35. CloseHandle( hFile );
  36. }
  37. return 0;
  38. }