home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwplascr.zip / XWPL0208.ZIP / tools / WPSReset / wpsreset.c < prev   
C/C++ Source or Header  |  2002-02-26  |  3KB  |  101 lines

  1.  
  2. /*
  3.  * wpsreset.c:
  4.  *      this resets the WPS using PrfReset(). This API was originally
  5.  *      intended to change the user INI file (OS2.INI) and will then
  6.  *      restart the WPS. But this also works if you call it with the
  7.  *      current user INI file. ;-)
  8.  *
  9.  *      I suppose the WPS reacts to the PL_ALTERED msg which is
  10.  *      broadcast to all msg queues on the system by terminating
  11.  *      itself. The first instance of PMSHELL.EXE will then restart
  12.  *      the WPS.
  13.  *
  14.  *      WPSRESET only works if you pass it the "-D" parameter on the
  15.  *      command line in order to prevent accidental Desktop restarts.
  16.  *      I don't remember what "-D" stands for. Maybe "dumb".
  17.  *
  18.  *      Copyright (C) 1997-2002 Ulrich Möller.
  19.  *      This program is free software; you can redistribute it and/or modify
  20.  *      it under the terms of the GNU General Public License as published by
  21.  *      the Free Software Foundation, in version 2 as it comes in the COPYING
  22.  *      file of the XWorkplace main distribution.
  23.  *      This program is distributed in the hope that it will be useful,
  24.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  *      GNU General Public License for more details.
  27.  */
  28.  
  29. #include <stdlib.h>
  30. #define INCL_WIN
  31. #include <os2.h>
  32. #include <string.h>
  33. #include <stdio.h>
  34.  
  35. #include "bldlevel.h"
  36.  
  37. void Error(PSZ psz)
  38. {
  39.     printf("wpsreset: %s\n", psz);
  40. }
  41.  
  42. int main(int argc, char *argv[])
  43. {
  44.     BOOL    fContinue = FALSE;
  45.     HAB     habShutdown = WinInitialize(0);
  46.     HMQ     hmq = WinCreateMsgQueue(habShutdown, 0);
  47.  
  48.     if (argc == 2)
  49.         // check for "-D" parameter
  50.         if (strcmp(argv[1], "-D") == 0)
  51.             fContinue = TRUE;
  52.  
  53.     if (fContinue)
  54.     {
  55.         // find out current profile names
  56.         PRFPROFILE Profiles;
  57.         Profiles.cchUserName = Profiles.cchSysName = 0;
  58.         // first query their file name lengths
  59.         if (PrfQueryProfile(habShutdown, &Profiles))
  60.         {
  61.             // allocate memory for filenames
  62.             Profiles.pszUserName  = malloc(Profiles.cchUserName);
  63.             Profiles.pszSysName  = malloc(Profiles.cchSysName);
  64.  
  65.             if (Profiles.pszSysName)
  66.             {
  67.                 // get filenames
  68.                 if (PrfQueryProfile(habShutdown, &Profiles))
  69.                 {
  70.  
  71.                     // "change" INIs to these filenames:
  72.                     // THIS WILL RESET THE WPS
  73.                     if (PrfReset(habShutdown, &Profiles) == FALSE)
  74.                         Error("Unable to reset profiles.");
  75.                     free(Profiles.pszSysName);
  76.                     free(Profiles.pszUserName);
  77.                 }
  78.                 else
  79.                     Error("Unable to query profile file names.");
  80.             }
  81.             else
  82.                 Error("Out of memory.");
  83.         }
  84.         else
  85.             Error("Unable to query profile file name sizes.");
  86.     }
  87.     else
  88.     {
  89.         printf("wpsreset V"BLDLEVEL_VERSION" ("__DATE__") (C) 1998-2002 Ulrich Möller\n");
  90.         printf("Restarts the Workplace Shell process.\n");
  91.         printf("Usage: wpsreset -D\n");
  92.     }
  93.  
  94.  
  95.     WinDestroyMsgQueue(hmq);
  96.     WinTerminate(habShutdown);
  97.  
  98.     return (0);
  99. }
  100.  
  101.