Example: Administration APIs

This example demonstrates how an application might use iSeries™ Access for Windows® Administration APIs.

In this example, the APIs are used to get and display:

The user then is allowed to enter iSeries Navigator plug-in names, and is informed whether the plug-in is installed.

Usage notes:

Include cwbad.h *

Link with cwbapi.lib

Example

#include <windows.h>
#include <stdio.h>
 
#include "cwbad.h"


/*
 *  This is the highest numbered component ID known (it is
 *  the ID of the last component defined in cwbad.h).
 */
#define LAST_COMPID_WE_KNOW_ABOUT       (CWBAD_COMP_SSL_40_BIT)


/*
 *  Array of component names, taken from comments for component IDs
 *  in cwbad.h, so human-readable component descriptions are displayed .
 *  In the compDescr array, the component ID for a component must match
 *  the index in the array of that component's description.
 *
 *  For a blank or unknown component name, a string is provided to display
 *  an indication that the component ID is unknown, and what that ID is.
 */
static char* compDescr[ LAST_COMPID_WE_KNOW_ABOUT + 1 ] = {
                              "",                            // #0 is not used
                              "Required programs",
                              "Optional Components",
                              "Directory Update",
                              "Incoming Remote Command",
                              "", // not used, 
                              "Online User's Guide",
                              "iSeries Navigator",
                              "Data Access",
                              "Data Transfer",
                              "Data Transfer Base Support",
                              "Data Transfer Excel Add-in",
                              "Data Transfer WK4 file support",
                              "ODBC",
                              "OLE DB Provider",
                              "AFP Workbench Viewer",
                              "iSeries Java Toolbox",
                              "5250 Display and Printer Emulator",
                              "Printer Drivers",
                              "AFP printer driver",
                              "SCS printer driver",
                              "iSeries Operations Console",
                              "iSeries Access Programmer's Toolkit",
                              "Headers, Libraries, and Documentation",
                              "Visual Basic Wizards",
                              "EZ Setup",
                              "Java Toolkit",
                              "Screen customizer",
                              ".NET Data Provider",
                              "",                       //-------------#29
                              "", "", "", "", "",       //             #30-34
                              "", "", "", "", "",       //             #35-39
                              "", "", "", "", "",       //             #40-44
                              "", "", "", "", "",       //             #45-49
                              "", "", "", "", "",       //   not       #50-54
                              "", "", "", "", "",       //             #55-59
                              "", "", "", "", "",       //             #60-64
                              "", "", "", "", "",       //             #65-69
                              "", "", "", "", "",       //   used      #70-74
                              "", "", "", "", "",       //             #75-79
                              "", "", "", "", "",       //             #80-84
                              "", "", "", "", "",       //             #85-89
                              "", "", "", "", "",       //             #90-94
                              "", "", "", "", "",       //------------ #95-99
                              "iSeries Navigator Base Support",
                              "iSeries Navigator Basic Operations",
                              "iSeries Navigator Job Management",
                              "iSeries Navigator System Configuration",
                              "iSeries Navigator Networks",
                              "iSeries Navigator Security",
                              "iSeries Navigator Users and Groups",
                              "iSeries Navigator Database",
                              "",                       // not used      #108
                              "iSeries Navigator Backup",
                              "iSeries Navigator Application Development",
                              "iSeries Navigator Application Administrat",
                              "iSeries Navigator File Systems",
                              "iSeries Navigator Management Central",
                              "iSeries Navigator Management Central - Commands",
                              "iSeries Navigator Management Central - Packages and Products",
                              "iSeries Navigator Logical Systems",
                              "iSeries Navigator Advanced Function Presentation",
                              "",""                 //-------------#118-119
                              "", "", "", "", "",   //  not        #120-124
                              "", "", "", "", "",   //             #125-129
                              "", "", "", "", "",   //             #130-134
                              "", "", "", "", "",   //  used       #135-139
                              "", "", "", "", "",   //             #140-144
                              "", "", "", "", "",   //------------ #145-149
                              "PC5250: BASE_KOREAN",
                              "PC5250: PDFPDT_KOREAN",
                              "PC5250: BASE_SIMPCHIN",
                              "PC5250: PDFPDT_SIMPCHIN",
                              "PC5250: BASE_TRADCHIN",
                              "PC5250: PDFPDT_TRADCHIN",
                              "PC5250: BASE_STANDARD",
                              "PC5250: PDFPDT_STANDARD",
                              "PC5250: FONT_ARABIC",
                              "PC5250: FONT_BALTIC",
                              "PC5250: FONT_LATIN2",
                              "PC5250: FONT_CYRILLIC",
                              "PC5250: FONT_GREEK",
                              "PC5250: FONT_HEBREW",
                              "PC5250: FONT_LAO",
                              "PC5250: FONT_THAI",
                              "PC5250: FONT_TURKISH",
                              "PC5250: FONT_VIET",
                              "PC5250: FONT_HINDI",
                              "",                   //------------ #169
                              "", "", "", "", "",   //             #170-174
                              "", "", "", "", "",   //  not        #175-179
                              "", "", "", "", "",   //             #180-184
                              "", "", "", "", "",   //  used       #185-189
                              "", "", "", "", "",   //             #190-194
                              "", "", "", "", "",   //------------ #195-199
                              "Secure Sockets Layer (SSL)" } ;       // last one defined
static char  unknownComp[] = "unknown, ID=          ";
static char* pInsertID     = &amp;( unknownComp[12] );          // insert ID here!




/**************************************************************************
 *  Show the iSeries Access for Windows Version/Release/Modification level
 **************************************************************************/
void showCA_VRM()
{
   ULONG  caVer, caRel, caMod;
   UINT   rc;
   char   fixlevelBuf[ MAX_PATH ];
   ULONG  fixlevelBufLen = sizeof( fixlevelBuf );

   printf( "iSeries Access level installed:\n\n" );

   rc = cwbAD_GetClientVersion( &caVer;, &caRel;, &caMod; );
   if ( rc != CWB_OK )
   {
      printf( "   Error %u occurred when calling cwbAD_GetClientVersion()\n\n",
         rc );
   }
   else
   {
      printf( "   Version %lu, Release %lu, Modification %lu\n\n",
         caVer, caRel, caMod );

      printf( "iSeries Access service pack level installed:\n\n" );
      rc = cwbAD_GetProductFixLevel( fixlevelBuf, &fixlevelBufLen; );
      if ( rc != CWB_OK )
      {
         printf( "   Error %u occurred when calling "
            "cwbAD_GetProduceFixLevel()\n\n", rc );
      }
      else if ( fixlevelBuf[0] == '\0' )  // empty, no service packs applied
      {
         printf( "   None\n\n" );
      }
      else
      {
         printf( "   %s\n\n", fixlevelBuf );
      }
   }
}



/**************************************************************************
 *  Call iSeries Access for Windows API to determine if the component is installed,
 *  and pass back:
 *      NULL if the component is not installed or an error occurs,
 *             OR
 *      A string indicating the component name is unknown if the
 *      component ID is higher than we know about OR the component
 *      description is blank,
 *             OR
 *      The human-readable component description if known.
 **************************************************************************/
char* isCompInstalled( ULONG compID )
{
   cwb_Boolean bIsInstalled;
   char*       pCompName;

   UINT rc = cwbAD_IsComponentInstalled( compID, &bIsInstalled; );

   /*
    *  Case 1:  Error OR component not installed, return NULL to
    *           indicate not installed.
    */
   if ( ( rc != CWB_OK ) || ( bIsInstalled == CWB_FALSE ) )
   {
      pCompName = NULL;
   }

   /*
    *  Case 2:  Component IS installed, but its name is not known,
    *           return component name unknown string.
    */
   else if ( ( compID > LAST_COMPID_WE_KNOW_ABOUT ) ||
             ( compDescr[ compID ][ 0 ] == '\0' ) )
   {
      pCompName = unknownComp;
      sprintf( pInsertID, "%lu", compID );
   }

   /*
    *  Case 3:  Component IS installed, and a name is known, return it
    */
   else
   {
      pCompName = compDescr[ compID ];
   }

   return pCompName;
}



/**************************************************************************
 *  List the iSeries Access for Windows components that currently are installed.
 **************************************************************************/
void showCA_CompInstalled()
{
   ULONG compID;
   char* compName;

   printf( "iSeries Access components installed:\n\n" );

   /*
    *  Try all known components, plus a bunch more in case some
    *  have been added (via service pack).
    */
   for ( compID = 0;
         compID &lt; (LAST_COMPID_WE_KNOW_ABOUT + 50);
         compID++ )
   {
      compName = isCompInstalled( compID );
      if ( compName != NULL )
      {
         printf( "   %s\n", compName );
      }
   }

   printf( "\n" );
}



/**************************************************************************
 *  MAIN PROGRAM BODY
 **************************************************************************/
void main(void)
{
   UINT         rc;
   char         pluginName[ MAX_PATH ];
   cwb_Boolean  bPluginInstalled;

   printf( "=======================================\n");
   printf( "iSeries Access What's Installed Reporter\n" );
   printf( "=======================================\n\n");

   showCA_VRM();
   showCA_CompInstalled();

   /*
    *  Allow user to ask by name what plug-ins are installed.
    */
   while ( TRUE )  /* REMINDER: requires a break to exit the loop! */
   {
      printf( "Enter plug-in to check for, or DONE to quit:\n" );
      gets( pluginName );
      if ( stricmp( pluginName, "DONE" ) == 0 )
      {
         break;    /* exit from the while loop, DONE at user's request */
      }

      rc = cwbAD_IsOpNavPluginInstalled( pluginName, &bPluginInstalled; );
      if ( rc == CWB_OK )
      {
         if ( bPluginInstalled == CWB_TRUE )
         {
            printf( "The plug-in '%s' is installed.\n\n", pluginName );
         }
         else
         {
            printf( "The plug-in '%s' is NOT installed.\n\n", pluginName );
         }
      }
      else
      {
         printf(
           "Error %u occurred when calling cwbAD_IsOpNavPluginInstalled.\n\n",
           rc );
      }
   }  // end while (TRUE)

   printf( "\nEnd of program.\n\n" );
}