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

  1. /* GetSKeys - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function searches the MS Windows 95/NT System Registry,
  6. **      enumerating all RunServices key values it finds.
  7. **
  8. **      Called:     list = Handle to the ListView control to be filled.
  9. **
  10. **      Returns:    TRUE upon success, or FALSE if an error exists.
  11. **
  12. **      Notes:      This routine searchs the follow key:
  13. **
  14. **                      HKEY_LOCAL_MACHINE
  15. **                        Software
  16. **                          Microsoft
  17. **                            Windows
  18. **                              CurrentVersion
  19. **                                RunServices
  20. **                                  Title = d:\folder\program.exe /flags
  21. **
  22. */
  23.  
  24. #include "AppPaths.h"
  25.  
  26. extern BOOL far GetSKeys (HWND list)
  27. {
  28.     auto HKEY       key     = NULL;
  29.     auto DWORD      inx     = NIL;
  30.     auto LV_ITEM    item    = { NIL };
  31.  
  32.     auto LONG       err;
  33.     auto DWORD      size;
  34.     auto DWORD      len;
  35.  
  36.     auto char       sub[PSTRING];
  37.     auto char       value[PSTRING];
  38.  
  39.     auto char       srv[PSTRING];
  40.  
  41.     lstrcpy (sub,REGSTR_PATH_RUNSERVICES);
  42.  
  43.     err = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  44.                         sub,
  45.                         NIL,
  46.                         KEY_READ,
  47.                         &key);
  48.  
  49.     if (err != ERROR_SUCCESS)
  50.         return (FALSE);
  51.  
  52.     ListView_DeleteAllItems (list);
  53.  
  54.     do {
  55.  
  56.         size = PSTRING;
  57.         len  = PSTRING;
  58.  
  59.         if ((err = RegEnumValue (key,inx,value,&size,NULL,NULL,(LPBYTE) srv,&len)) != ERROR_SUCCESS) {
  60.             inx++;
  61.             continue;
  62.             }
  63.  
  64.         item.mask = LVIF_TEXT;
  65.  
  66.         item.iItem = inx;
  67.         item.iSubItem = COLUMN_1;
  68.         item.pszText = value;
  69.         
  70.         ListView_InsertItem (list,&item);
  71.         ListView_SetItemText (list,inx,COLUMN_2,srv);
  72.  
  73.         inx++;
  74.  
  75.         } while (err != ERROR_NO_MORE_ITEMS);
  76.  
  77.     if (key) RegCloseKey (key);
  78.  
  79.     return ((inx) ? TRUE : FALSE);
  80. }
  81.  
  82. /* end of GetSKeys.c - written by Gregory Braun */
  83.