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.

57 lines
1.3 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. DWORD
  5. TSNewSource(
  6. IN LPTSTR ServerName,
  7. IN LPTSTR SourceName,
  8. IN DWORD Reserved
  9. );
  10. _cdecl
  11. main(int argc, char ** argv)
  12. {
  13. DWORD err;
  14. LPSTR server;
  15. LPWSTR serverName;
  16. WCHAR computerName[MAX_COMPUTERNAME_LENGTH+1];
  17. DWORD computerNameSize = MAX_COMPUTERNAME_LENGTH+1;
  18. server = getenv( "TargetSystem" );
  19. if ( server == NULL ) {
  20. printf("Please define 'TargetSystem' first!\n");
  21. return(1);
  22. }
  23. serverName = LocalAlloc( LMEM_ZEROINIT, (strlen(server) + 1) * sizeof(WCHAR) );
  24. if ( serverName == NULL ) {
  25. printf("Failed to allocate a %d byte buffer!\n",
  26. (strlen(server) + 1) * sizeof(WCHAR) );
  27. return(1);
  28. }
  29. if ( argc > 1 ) {
  30. printf("usage: %s\n", *argv);
  31. return(1);
  32. }
  33. mbstowcs( serverName, server, strlen(server) );
  34. err = GetComputerNameW( computerName, &computerNameSize );
  35. if ( !err ) {
  36. printf("Failed to get local computer name, error %d\n", err);
  37. return(1);
  38. }
  39. printf("Telling %s to use local system (%ws) as a time source!\n",
  40. server, computerName);
  41. err = TSNewSource(serverName,
  42. computerName,
  43. 0);
  44. printf("status = %d\n", err);
  45. return(0);
  46. }