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.

99 lines
2.2 KiB

  1. /****************************************************************************/
  2. // winping.c
  3. //
  4. // Copyright (C) 1997-1999 Microsoft Corp.
  5. /****************************************************************************/
  6. #include <nt.h>
  7. #include <ntrtl.h>
  8. #include <nturtl.h>
  9. #include <ntddkbd.h>
  10. #include <ntddmou.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <wchar.h>
  15. #include <windows.h>
  16. #include <winsta.h>
  17. /*
  18. * Include the RPC generated common header
  19. */
  20. #include "tsrpc.h"
  21. int _cdecl
  22. main (int argc, char *argv[])
  23. {
  24. HANDLE hLocal;
  25. NTSTATUS Status;
  26. DWORD Result;
  27. int i;
  28. WCHAR *CmdLine;
  29. WCHAR **argvW;
  30. if ( argc != 2 ) {
  31. printf( "winping: WinStation Ping utility\n" );
  32. printf( "USAGE: winping <Machine>\n" );
  33. return( 1 );
  34. }
  35. CmdLine = GetCommandLineW();
  36. argvW = (WCHAR **)malloc( sizeof(WCHAR *) * (argc+1) );
  37. if(argvW == NULL) {
  38. exit(1);
  39. }
  40. argvW[0] = wcstok(CmdLine, L" ");
  41. for(i=1; i < argc; i++){
  42. argvW[i] = wcstok(0, L" ");
  43. }
  44. argvW[argc] = NULL;
  45. printf(" Pinging Local SERVERNAME_CURRENT\n");
  46. Result = WinStationServerPing( SERVERNAME_CURRENT );
  47. printf(" Result from 0x%x\n",Result,GetLastError());
  48. if( _wcsicmp(L"LOCAL", argvW[1]) == 0 ) {
  49. printf("Opening machine name NULL (per context local)\n");
  50. hLocal = WinStationOpenServerW(
  51. NULL // Machine name
  52. );
  53. if( hLocal == NULL ) {
  54. printf("Error %d Opening Local Server over LPC\n",GetLastError());
  55. exit(1);
  56. }
  57. }
  58. else {
  59. printf("Opening machine name %ws\n",argvW[1]);
  60. hLocal = WinStationOpenServerW(
  61. argvW[1] // Machine name
  62. );
  63. if( hLocal == NULL ) {
  64. printf("Error %d Opening Remote Server %ws over NP\n",GetLastError(),argvW[1]);
  65. exit(1);
  66. }
  67. }
  68. Result = WinStationServerPing( hLocal );
  69. printf("Result from WinStationServerPing 0x%x\n",Result);
  70. Result = WinStationCloseServer( hLocal );
  71. printf("Result from WinStationCloseServer is 0x%x\n",Result);
  72. printf("Sleeping.....\n");
  73. SleepEx(1000*30, TRUE);
  74. return( 0 );
  75. }