home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / ntcode / ntperlb / nt / registry.txt < prev    next >
Encoding:
Text File  |  1995-05-19  |  10.5 KB  |  307 lines

  1. -----------------------------------------------------------------------------
  2. Registry.txt
  3. -----------------------------------------------------------------------------
  4.  
  5. This file documents the extentions to Perl for NT that allow perl
  6. scripts access to the NT registry database. All Registry API's have
  7. been duplicated as user defined perl subroutines, with the exception
  8. of RegNotifyChangeKeyValue. This routine was not implemented due to
  9. time constraints and due to it's usefulness in perl scripts not being
  10. immediately apparent. It may be implemented in the future.
  11.  
  12. IMPORTANT NOTE: It is possible to make your system unbootable by
  13. corrupting the registry database! Use EXTREME caution when writing a
  14. perl script that updates the registry! Also note that none of the
  15. routines that actually modify the files that comprise the registry
  16. have been tested. Only the routines that read or write keys/values in
  17. the existing registry have been tested.
  18.  
  19. The Perl registry access subroutines nearly duplicate the Win32 API
  20. for registry calls.  Although they are not perl-like, it was felt that
  21. the perl calls should look as nearly like the documentation provided
  22. with NT as possible. Hopefully this will minimize confusion when using
  23. them.
  24.  
  25. The main difference between the C registry routines and the perl
  26. versions of them is that whenever a size option is specified as an
  27. argument to a C routine, that parameter is omitted from the perl
  28. version, since perl already knows how big a scalar is and will
  29. dynamically size a parameter used to return a value. If a registry
  30. access routine is called incorrectly in a perl script, it will print a
  31. usage message and the perl script will abort.
  32.  
  33. Note that all arguments to the perl registry routines are SCALARS.
  34. Passing in arrays to the enumeration functions would be convienent, so
  35. that it would not be nessesary to iterate when enumerating keys or
  36. values, but again, time constraints interferred. This feature may be
  37. implemented in a later release.
  38.  
  39. Some routines are documented in the Win32 API help file as having been
  40. provided only for Windows 3.1 compatiblity. These routines include
  41. RegCreateKey, RegOpenKey, RegEnumKey, RegQueryValue, and RegSetValue.
  42. All of these routines have new versions with "Ex" appended to their
  43. names which are the preferred version for use in new applications. In
  44. implementing these routines in the Perl interpreter, all calls were
  45. made to the new and improved versions of these routines so that
  46. compatibility problems will be avoided when Microsoft upgrades
  47. software. So, a perl script making the call:
  48.  
  49.     &RegOpenKey($HKEY_LOCAL_MACHINE, "SOFTWARE\\Intergraph", $h);
  50.  
  51. actually boils down to a call to RegOpenKeyEx with appropriate
  52. defaults in the perl interpreter. 
  53.  
  54. For more information on the contents of the registry and on accessing
  55. the registry, see the help file for the registry editor (RegEdit), the
  56. API documentation in the Win32 API help file, and the Microsoft
  57. Windows NT Resource Guide (Preliminary March 1993).
  58.  
  59.    Conventions:
  60.  
  61.         $hkey: refers to a key handle value. Either one of the
  62.                predefined variables or a value returned from 
  63.                RegOpenKey[Ex] or RegCreateKey[Ex].
  64.  
  65.         $newhkey: the parameter where a new handle will be returned.
  66.  
  67.         $subkey: a string used as a subkey of the specified key
  68.                  handle.
  69.  
  70.         $sam: a security access mask (on of the $KEY_* variables).
  71.  
  72.         $valname: a scalar that either specifies a value name or
  73.                   receives a value name.
  74.  
  75.         $index: a unsigned integer used when enumerating subkeys or
  76.                 values of a key.
  77.  
  78.         $reserved: a parameter that Microsoft has reserved for future
  79.                    use. Should be zero, but in fact is ignored.
  80.  
  81.     All of the Registry access routines return a success or failure
  82.     status with the actual return value from the routine in $!. This
  83.     allows you to write code such as this:
  84.  
  85.         $keystring = "SOFTWARE\\Description\\Intergraph\\Perl";
  86.         &RegCreateKey($HKEY_LOCAL_MACHINE, $keystring, $newhkey) ||
  87.                 die "Can't open $keystring: $!\n";
  88.  
  89.     If the call to RegCreateKeyEx fails then it's error code is
  90.     stored in $!. The failure status causes the die routine to be
  91.     called which prints the string corresponding to the error number
  92.     and then terminates the perl process.
  93.  
  94.  
  95.  
  96. Variables:
  97.  
  98. All of the variables needed for accessing the NT registry are now
  99. defined in the file registry.pl, in the perl library directory. To
  100. access these values, put a require statment in your perl script, i.e.: 
  101.  
  102.     require "registry.pl";
  103.  
  104.  
  105.  Pre-defined key handles
  106.  
  107.     $HKEY_CLASSES_ROOT
  108.     $HKEY_CURRENT_USER
  109.     $HKEY_LOCAL_MACHINE
  110.     $HKEY_USERS
  111.  
  112.  Security Access Mask values
  113.  
  114.     $KEY_ALL_ACCESS
  115.     $KEY_CREATE_SUB_KEY
  116.     $KEY_ENUMERATE_SUB_KEYS
  117.     $KEY_EXECUTE
  118.     $KEY_NOTIFY
  119.     $KEY_QUERY_VALUE
  120.     $KEY_READ
  121.     $KEY_SET_VALUE
  122.     $KEY_WRITE
  123.  
  124.  Data types from the registry
  125.  
  126.     $REG_BINARY  - binary data
  127.     $REG_DWORD - 32 bit value
  128.     $REG_DWORD_LITTLE_ENDIAN - 32 bit value in little endian byte order
  129.     $REG_DWORD_BIG_ENDIAN - 32 bit value in big endian (network) byte order
  130.     $REG_EXPAND_SZ - null terminated string with environment variables
  131.     $REG_LINK - symbolic link within registry
  132.     $REG_MULTI_SZ - multiple null terminated strings
  133.     $REG_NONE - no type associated with this value
  134.     $REG_RESOURCE_LIST - device resource list
  135.     $REG_SZ - null terminated string
  136.  
  137.  Open/Create Options
  138.  
  139.     $REG_OPTION_RESERVED
  140.     $REG_OPTION_NON_VOLATILE
  141.     $REG_OPTION_VOLATILE
  142.     $REG_OPTION_CREATE_LINK
  143.  
  144.  Key creation/open disposition
  145.  
  146.     $REG_CREATED_NEW_KEY
  147.     $REG_OPENED_EXISTING_KEY
  148.  
  149.  Key restore flags
  150.  
  151.     $REG_WHOLE_HIVE_VOLATILE
  152.     $REG_REFRESH_HIVE
  153.  
  154.  
  155. Subroutines:
  156.  
  157. The following routines have been tested:
  158.  
  159. &RegCloseKey ($hkey)
  160.     $hkey - an open key handle from a call to RegCreateKey,
  161.             RegCreateKeyEx, RegOpenKey, or RegOpenKeyEx. 
  162.  
  163. &RegCreateKey ($hkey, $subkey, $newhkey)
  164.     $hkey - open key handle.
  165.     $subkey - string value specifying subkey of currently open key.
  166.     $newhkey - new handle.
  167.  
  168. &RegCreateKeyEx ($hkey, $subkey, $reserved, $class, $options, $sam,
  169.                  $SecAttrib, $newhkey, $disposition)
  170.     $hkey - open key handle.
  171.     $subkey - string identifying the subkey to create/open
  172.     $reserved - ignored
  173.     $class - class name for new key
  174.     $options - indicates if new key is volatile or not
  175.     $sam - security access mask.
  176.     $SecAttrib - security attributes structure (packed data)
  177.     $newhkey - new handle.
  178.     $disposition - 
  179.  
  180. &RegDeleteKey ($hkey, $subkey)
  181.     $hkey - open key handle
  182.     $subkey - string identifying the subkey to delete
  183.  
  184. &RegDeleteValue ($hkey, $valname);
  185.     $hkey - open key handle
  186.     $valname - name of value to delete
  187.  
  188. &RegEnumKey ($hkey, $index, $subkey)
  189.     $hkey - open key handle
  190.     $index - numeric index of key to enumerate
  191.     $subkey - returned key name
  192.  
  193. &RegEnumKeyEx ($hkey, $index, $subkey, $reserved, $class, $time)
  194.     $hkey - open key handle
  195.     $index - numeric index of key to enumerate
  196.     $subkey - returned key name
  197.     $reserved - must be zero
  198.     $class - returned class name of $subkey
  199.     $time - time of last modification of $subkey
  200.     
  201. &RegEnumValue ($hkey, $index, $valname, $reserved, $type, $data)
  202.     $hkey - open key handle
  203.     $index - numeric index of key to enumerate
  204.     $valname - returned value name
  205.     $reserved - must be zero
  206.     $type - returned type of $valname
  207.     $data - data associated with $valname (of data type $type)
  208.  
  209. &RegFlushKey ($hkey)
  210.     $hkey - open key handle
  211.  
  212. &RegGeyKeySecurity ($hkey, $SecInf, $SecDesc)
  213.     $hkey - open key handle
  214.     $SecInf - Security information structure (packed)
  215.     $SecDesc - returned Security Descriptor data (packed)
  216.  
  217. &RegLoadKey ($hkey, $subkey, $file)
  218.     $hkey - open key handle
  219.     $subkey - string identifying subkey of $key
  220.     $file - string identifying filename to load information from
  221.  
  222. &RegOpenKey ($hkey, $subkey, $newhkey)
  223.     $hkey - open key handle
  224.     $subkey - string identifying subkey of $key
  225.     $newhkey - returned key handle
  226.     
  227. &RegOpenKeyEx ($hkey, $subkey, $reserved, $sam, $newhkey)
  228.     $hkey - open key handle
  229.     $subkey - string identifying subkey of $key
  230.     $reserved - must be zero
  231.     $sam - requested security access mask
  232.     $newhkey - returned key handle
  233.  
  234. &RegQueryInfoKey ($hkey, $class, $reserved, $nsubkeys, $maxsubkey, 
  235.                   $maxclass, $nvalues, $maxvalname, $maxvaldata,
  236.                   $SecDesc, $time)
  237.     $hkey - open key handle
  238.     $class - returned key class (string)
  239.     $reserved - must be zero
  240.     $nsubkey - number of subkeys for this key
  241.     $maxsubkey - size of largest subkey
  242.     $maxclass - size of largest class name
  243.     $nvalues - number of values associated with this key
  244.     $maxvalname - size of largest value name
  245.     $manvaldata - size of largest value data
  246.     $SecDesc - Security Descriptor (packed data)
  247.     $time - time of last write
  248.  
  249. &RegQueryValue ($hkey, $subkey, $value)
  250.     $hkey - open key handle
  251.     $subkey - string identifying the subkey of key to query
  252.     $value - returned value for first NULL valname
  253.  
  254. &RegQueryValueEx ($hkey, $valname, $reserved, $type, $data)
  255.     $hkey - open key handle
  256.     $valname - string identifying value to retreive
  257.     $reserved - must be zero
  258.     $type - returned type of $data
  259.     $data - returned data associated with $valname
  260.  
  261. &RegReplaceKey ($hkey, $subkey, $newfile, $oldfile)
  262.     $hkey - open key handle
  263.     $subkey - string identifying subkey of $key
  264.     $newfile - file to put into registry
  265.     $oldfile - name for old registry file
  266.  
  267. &RegRestoreKey ($hkey, $file, $flags)
  268.     $hkey - open key handle
  269.     $file - name of file to restore key from
  270.     $flags - indicates if key data is volatile
  271.  
  272. &RegSaveKey ($hkey, $file, $SecAttrib)
  273.     $hkey - open key handle
  274.     $file - file in which to save key and subkeys.
  275.     $SecAttrib - security attributes for new file (packed data)
  276.  
  277. &RegSetKeySecurity ($hkey, $SecInf, $SecDesc);
  278.     $hkey - open key handle
  279.     $SecInf - Security Information structure (packed data)
  280.     $SecDesc - Security Descriptor structure (packed data)
  281.  
  282. &RegSetValue ($hkey, $subkey, $type, $data)
  283.     $hkey - open key handle
  284.     $subkey - string indentifying subkey 
  285.     $type - data type of $data
  286.     $data - data to associate with $subkey (NULL name)
  287.  
  288. &RegSetValueEx ($hkey, $valname, $reserved, $type, $data)
  289.     $hkey - open key handle
  290.     $valname - name of value to set
  291.     $reserved - must be zero
  292.     $type - data type of $data
  293.     $data - data to associate with valname
  294.  
  295. The following routine have NOT been tested:
  296.  
  297. &RegConnectRegistry ($machine, $hkey, $newhkey)
  298.     $machine - name of an NT system.
  299.     $hkey - one of $HKEY_LOCAL_MACHINE or $HKEY_USERS.
  300.     $newkey - new handle for access on remote machine.
  301.  
  302. &RegUnLoadKey ($hkey, $subkey)
  303.     $hkey - open key handle
  304.     $subkey - string that identifies subkey tree to be unloaded
  305.  
  306.  
  307.