home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / sndmes.exe / SENDMESS.C next >
Text File  |  1995-06-23  |  3KB  |  122 lines

  1.  /****************************************************************************
  2. **      DISCLAIMER  
  3. **  
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.  
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **   
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ***************************************************************************/
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #define NWDOS
  24.  
  25. #include <nwcalls.h>
  26.  
  27. void main (int argc, char *argv[])
  28. {
  29.     NWCCODE    ccode;
  30.     NWCONN_HANDLE    conn;
  31.     NWNUMBER    maxConns;
  32.     NWOBJ_ID    userID, ID;
  33.     NWFLAGS    flag;
  34.  
  35.     int i;
  36.     char    message[256];
  37.     char    server[50];
  38.     char    user[50];
  39.  
  40.     if (argc < 4)
  41.     {
  42.         printf ("Usage:  SENDMESS serverName userName message\n");
  43.         printf ("You must be logged in to the server\n");
  44.         return;
  45.     }
  46.  
  47.     strcpy (server, strupr (argv[1]));
  48.     strcpy (user, strupr (argv[2]));
  49.     strcpy (message, "");
  50.  
  51.     for (i = 3; i < argc; i++)
  52.     {
  53.         strcat (message, argv[i]);
  54.         strcat (message, " ");
  55.     }
  56.     message[strlen (message) - 1] = '\x0';
  57.  
  58.     ccode = NWCallsInit (NULL,NULL);
  59.     if (ccode)    return;
  60.  
  61.     ccode = NWGetConnectionHandle (server, 0, &conn, NULL);
  62.     if (ccode)
  63.     {
  64.         printf ("NWGetConnectionHandle returned %X\n", ccode);
  65.         return;
  66.     }
  67.  
  68.     ccode = NWGetObjectID (conn, user, OT_USER, &userID);
  69.     if (ccode)
  70.     {
  71.         printf ("NWGetObjectID returned %X\n", ccode);
  72.         return;
  73.     }
  74.  
  75.     ccode = NWGetFileServerInformation (
  76.         conn,
  77.         NULL,
  78.         NULL,
  79.         NULL,
  80.         NULL,
  81.         &maxConns,
  82.         NULL,
  83.         NULL,
  84.         NULL,
  85.         NULL,
  86.         NULL);
  87.     if (ccode)
  88.     {
  89.         printf ("NWGetFileServerInformation returned %X\n", ccode);
  90.         return;
  91.     }
  92.  
  93.     for (i = 0; i < maxConns; i++)
  94.     {
  95.         NWGetConnectionInformation (conn, i, NULL, NULL, &ID, NULL);
  96.         if (ID == userID)    break;
  97.     }
  98.  
  99.     if (ID == userID)
  100.     {
  101.         ccode = NWSendBroadcastMessage (conn, message, 1,
  102.             (NWCONN_NUM_WORD NWFAR *) &i,
  103.             &flag);
  104.         if (ccode)
  105.         {
  106.             printf ("NWSendBroadcastMessage returned %X\n", ccode);
  107.             return;
  108.         }
  109.         if (flag)
  110.         {
  111.             printf ("Server return code was %X\n", flag);
  112.             return;
  113.         }
  114.         printf ("Message sent successfully\n");
  115.     }
  116.     else
  117.     {
  118.         printf ("User %s not found on server %s\n", user, server);
  119.         return;
  120.     }
  121. }
  122.