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.

102 lines
2.2 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. GetPs.c
  5. Abstract:
  6. Command line test for getting the preferred server.
  7. Author:
  8. Cory West [corywest] 14-Nov-95
  9. ***/
  10. #include "ndsapi32.h"
  11. int
  12. _cdecl main(
  13. int argc,
  14. char **argv
  15. ) {
  16. NTSTATUS ntstatus;
  17. IO_STATUS_BLOCK IoStatusBlock;
  18. OBJECT_ATTRIBUTES ObjectAttributes;
  19. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  20. HANDLE hRdr;
  21. WCHAR OpenString[] = L"\\Device\\Nwrdr\\*";
  22. UNICODE_STRING OpenName;
  23. BYTE Reply[64];
  24. //
  25. // Check the arguments.
  26. //
  27. if ( argc != 1 ) {
  28. printf( "Usage: getps\n" );
  29. printf( "Retrieves the current preferred server.\n" );
  30. return -1;
  31. }
  32. //
  33. // Set up the object attributes.
  34. //
  35. RtlInitUnicodeString( &OpenName, OpenString );
  36. InitializeObjectAttributes( &ObjectAttributes,
  37. &OpenName,
  38. OBJ_CASE_INSENSITIVE,
  39. NULL,
  40. NULL );
  41. ntstatus = NtOpenFile( &hRdr,
  42. DesiredAccess,
  43. &ObjectAttributes,
  44. &IoStatusBlock,
  45. FILE_SHARE_VALID_FLAGS,
  46. FILE_SYNCHRONOUS_IO_NONALERT );
  47. if ( !NT_SUCCESS(ntstatus) )
  48. return ntstatus;
  49. //
  50. // Call the nwrdr.
  51. //
  52. ntstatus = NtFsControlFile( hRdr,
  53. NULL,
  54. NULL,
  55. NULL,
  56. &IoStatusBlock,
  57. FSCTL_NWR_GET_PREFERRED_SERVER,
  58. NULL,
  59. 0,
  60. (PVOID) Reply,
  61. sizeof( Reply ) );
  62. if ( !NT_SUCCESS( ntstatus ) ) {
  63. printf( "No preferred server is currently set.\n" );
  64. goto ExitWithClose;
  65. }
  66. //
  67. // On success the output buffer contains a UNICODE_STRING
  68. // with the string packed in afterwards.
  69. //
  70. printf( "Preferred Server: %wZ\n", (PUNICODE_STRING) Reply );
  71. ExitWithClose:
  72. NtClose( hRdr );
  73. return ntstatus;
  74. }