home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / sharewar / apaths / APSOURCE.ZIP / MakePKey.c < prev    next >
C/C++ Source or Header  |  2001-03-26  |  2KB  |  84 lines

  1. /* MakePKey - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function creates an AppPath system registry entry.
  6. **
  7. **      Called:     path = a pointer to the PATH data structure to
  8. **                         be used as the values for this registry
  9. **                         key.
  10. **
  11. **      Returns:    TRUE upon success, or FALSE if an error exists.
  12. **
  13. **      Notes:      This routine creates the following MS Windows 95/NT
  14. **                  System Registry entry:
  15. **
  16. **                      HKEY_LOCAL_MACHINE
  17. **                        Software
  18. **                          Microsoft
  19. **                            Windows
  20. **                              CurrentVersion
  21. **                                App Paths
  22. **                                  APPLICATION.EXE = d:\path\application.exe
  23. **                                    Path = d:\folder
  24. */
  25.  
  26.  
  27. #include "AppPaths.h"
  28.  
  29. extern BOOL far MakePKey (LPPATH path)
  30. {
  31.     auto HKEY   key = NULL;
  32.     auto LONG   err = NIL;
  33.  
  34.     auto DWORD  size;
  35.     auto DWORD  result;
  36.  
  37.     auto char sub[PSTRING];
  38.  
  39.     wsprintf (sub,"%s\\%s",REGSTR_PATH_APPPATHS,path->name);
  40.  
  41.     err = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  42.                           sub,
  43.                           NIL,
  44.                           BLANK_STR,
  45.                           REG_OPTION_NON_VOLATILE,
  46.                           KEY_SET_VALUE,
  47.                           NULL,
  48.                           &key,
  49.                           &result);
  50.  
  51.     if (err != ERROR_SUCCESS)
  52.         return (FALSE);
  53.  
  54.     if (*path->application) {
  55.  
  56.         size = lstrlen (path->application) + 1;
  57.  
  58.         err = RegSetValueEx (key,
  59.                              BLANK_STR,
  60.                              NIL,
  61.                              REG_SZ,
  62.                              (CONST BYTE *) path->application,
  63.                              size);
  64.         }
  65.  
  66.     if (*path->path) {
  67.  
  68.         size = lstrlen (path->path) + 1;
  69.  
  70.         err = RegSetValueEx (key,
  71.                              "Path",
  72.                              NIL,
  73.                              REG_SZ,
  74.                              (CONST BYTE *) path->path,
  75.                              size);
  76.         }
  77.  
  78.     RegCloseKey (key);
  79.  
  80.     return ((err == ERROR_SUCCESS) ? TRUE : FALSE);
  81. }
  82.  
  83. /* end of MakePKey.c - written by Gregory Braun */
  84.