home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / prfres.zip / PRFRESET.C < prev    next >
Text File  |  1993-06-15  |  3KB  |  125 lines

  1. #define INCL_WIN
  2. //#define INCL_WINSHELLDATA
  3.  
  4. #include <os2.h>
  5.  
  6. #include <stdio.h>
  7. #include <malloc.h>
  8. #include <string.h>
  9.  
  10.  
  11. main(int argc, char *argv[], char *envp[])
  12. {
  13.    int         iRC = 0;
  14.    HAB         hab = (HAB)NULL;
  15.    PRFPROFILE  prf;
  16.    FILE       *pfTest;
  17.    BOOL        fbQuery;
  18.  
  19.    // at least on arg required
  20.    if ( argc < 2) {
  21.       printf( "Usage : %s (new_user_profile | ?)\n",
  22.               argv[ 0]);
  23.       return( 1);
  24.    } /* endif */
  25.  
  26.    // check whether simply a query
  27.    if ( strcmp( argv[ 1], "?") != 0) {
  28.  
  29.       // NO
  30.       fbQuery = FALSE;
  31.  
  32.       // test whether file exists
  33.       if ( ( pfTest = fopen( argv[ 1], "r")) != (FILE *)NULL) {
  34.          fclose( pfTest);
  35.       } else {
  36.          printf( "new_user_profile does NOT exist\n");
  37.          return( 1);
  38.       } /* endif */
  39.  
  40.    } else {
  41.       fbQuery = TRUE;
  42.    } /* endif */
  43.  
  44.    // RC == 2 :=> API error
  45.    iRC = 2;
  46.  
  47.    // get a HAB
  48.    if ( ( hab = WinInitialize( 0)) == (HAB)NULL) {
  49.       printf( "Error WinInitialize\n");
  50.       return( iRC);
  51.    } /* endif */
  52.  
  53.    // init structure
  54.    prf.cchUserName = 0L;
  55.    prf.pszUserName = (PSZ)NULL;
  56.    prf.cchSysName = 0L;
  57.    prf.pszSysName = (PSZ)NULL;
  58.  
  59.    // 1st query, get bufferlength
  60.    if ( PrfQueryProfile( hab, &prf)) {
  61.  
  62.       if ( prf.cchUserName > 0L && prf.cchSysName > 0L) {
  63.  
  64.          // allocate buffers
  65.          prf.pszUserName = (PSZ)malloc( (size_t)prf.cchUserName);
  66.          prf.pszSysName  = (PSZ)malloc( (size_t)prf.cchSysName);
  67.  
  68.          if ( prf.pszUserName != (PSZ)NULL && prf.pszSysName != (PSZ)NULL) {
  69.  
  70.             // now query the actual names
  71.             if ( PrfQueryProfile( hab, &prf)) {
  72.  
  73.                printf( "current user profile   : %s\n"
  74.                        "current system profile : %s\n",
  75.                        prf.pszUserName,
  76.                        prf.pszSysName);
  77.  
  78.                if ( !fbQuery) {
  79.  
  80.                   // set user profile buffer to arg
  81.                   prf.pszUserName = argv[ 1];
  82.                   prf.cchUserName = (ULONG)( strlen( argv[ 1]) + 1);
  83.    
  84.                   // do a reset
  85.                   if ( PrfReset( hab, &prf)) {
  86.    
  87.                      // and confirm the reset
  88.                      if ( PrfQueryProfile( hab, &prf)) {
  89.                         printf( "user profile set to    : %s\n",
  90.                                 prf.pszUserName);
  91.                      } else {
  92.                         printf( "Error PrfQueryProfile (3)\n");
  93.                      } /* endif */
  94.    
  95.                      iRC = 0;
  96.  
  97.                   } else {
  98.                      printf( "Error PrfReset\n");
  99.                   } /* endif */
  100.  
  101.                } else {
  102.                   iRC = 0;
  103.                } /* endif */
  104.  
  105.             } else {
  106.                printf( "Error PrfQueryProfile (2)\n");
  107.             } /* endif */
  108.  
  109.          } else {
  110.             printf( "Error malloc\n");
  111.          } /* endif */
  112.       } else {
  113.          printf( "Invalid buffer size : cchUserName = %lu, cchSysName = %lu\n",
  114.                  prf.cchUserName,
  115.                  prf.cchSysName);
  116.       } /* endif */
  117.    } else {
  118.       printf( "Error PrfQueryProfile (1)\n");
  119.    } /* endif */
  120.  
  121.    WinTerminate( hab);
  122.  
  123.    return( iRC);
  124. }
  125.