home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / whosdk.exe / WHO.C next >
C/C++ Source or Header  |  1994-09-29  |  4KB  |  124 lines

  1.  
  2. /****************************************************************************
  3. **        DISCLAIMER
  4. **
  5. **    Novell, Inc. makes no representations or warranties with respect to
  6. **    any NetWare software, and specifically disclaims any express or
  7. **    implied warranties of merchantability, title, or fitness for a
  8. **    particular purpose.
  9. **
  10. **    Distribution of any NetWare software is forbidden without the
  11. **    express written consent of Novell, Inc.  Further, Novell reserves
  12. **    the right to discontinue distribution of any NetWare software.
  13. **
  14. **    Novell is not responsible for lost profits or revenue, loss of use
  15. **    of the software, loss of data, costs of re-creating lost data, the
  16. **    cost of any substitute equipment or program, or claims by any party
  17. **    other than you.  Novell strongly recommends a backup be made before
  18. **    any software is installed.   Technical support for this software
  19. **    may be provided at the discretion of Novell.
  20. ****************************************************************************
  21. #define NWDOS
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <conio.h>
  26. #include <fcntl.h>
  27. #include <nwcalls.h>
  28.  
  29. void main(int argc, char *argv[])
  30. {
  31.  NWCCODE ccode;
  32.  NWCONN_HANDLE connHandle;
  33.  int  *lastRec;
  34.  CONN_USING_FILE fUse;
  35.  CONNS_USING_FILE fUsed;
  36.  char *ptr;
  37.  int  i;
  38.  char objectName[256];
  39.  NWOBJ_TYPE NWFAR *objectType;
  40.  NWOBJ_ID NWFAR *objectID;
  41.  BYTE NWFAR *loginTime;
  42.  
  43.  if (argc != 3)
  44.  {
  45.   printf ("\nUsage:  WHO <File Server Name> <Path and filename>");
  46.   return;
  47.  }
  48.  
  49.  memset (&fUse, 0, sizeof (fUse));
  50.  memset (&fUsed, 0, sizeof (fUsed));
  51.  
  52.  printf("\nScan Who is Using the File ...\n");
  53.  
  54.  ccode = NWCallsInit(NULL, NULL);
  55.  
  56. // printf("\nNWCallsInit returned: %04X", ccode);
  57.  if(ccode) {
  58.     printf("\nNWCallsInit Error: %d", ccode);
  59.     exit(1);
  60.    }
  61.  
  62.  ptr = strupr(argv[1]);  /* Convert Server Name to upper case */
  63.  
  64.  ccode = NWGetConnectionHandle(ptr, 0, &connHandle, 0);
  65. // printf("\nNWGetConnectionHandle returned: %04X", ccode);
  66.  
  67.  if(ccode) {
  68.     printf("\nNWGetConnectionHandle Error: %d", ccode);
  69.     exit(1);
  70.    }
  71.  
  72. // printf("\nString entered on command line is: %s", argv[2]);
  73.  
  74.  
  75.  ptr = strupr(argv[2]); /* Convert path to upper case */
  76.  
  77.  lastRec[0]=0; lastRec[1]='\0';
  78.  
  79.  do
  80.   {
  81.  
  82.   ccode = NWScanConnectionsUsingFile(
  83.      /* Conn Handle         */ connHandle,
  84.      /* Directory handle    */ 0,
  85.      /* path                */ ptr,
  86.      /* Last Record         */ lastRec,
  87.      /* File Use            */ &fUse,
  88.      /* File Used           */ &fUsed
  89.      );
  90.  
  91.   printf("\n NWScanConnectionsUsingFile returned %04X", ccode);
  92.  if(ccode) {
  93. //    printf("\nNWScanConnectionUsingFile Error: %d", ccode);
  94.     exit(1);
  95.    }
  96.  
  97. //  printf ("\n CONNS_USING_FILE.connCount = %d", fUsed.connCount);
  98.   if(fUsed.connCount==0) {
  99.      printf("\nSorry. No one is using the file.");
  100.      exit(1);
  101.     }
  102.  
  103.   if((ccode == 0) && (fUsed.connCount)) {
  104. //     printf("\nConnection number = %d", fUse.connNumber);
  105.      ccode=NWGetConnectionInformation(connHandle,
  106.                                       fUse.connNumber,
  107.                                       objectName,
  108.                                       objectType,
  109.                                       objectID,
  110.                                       loginTime);
  111.  
  112.      if(ccode) {
  113.         printf("\nNWGetConnectionInformation Error: %d", ccode);
  114.         exit(1);
  115.        }
  116.  
  117.      printf("\n%s", objectName);
  118.     }
  119.  
  120.   }
  121.  while((!ccode) && (fUsed.connCount));
  122.  
  123. }
  124.