Dealing with the Windows Registry

Both, the .NET Registry class as well as the .NET RegistryKey class offer better support for accessing the Windows registry than the DLL calls offered in the past.

Note that the example function contains some code that can work under .NET 2.0 or better only. The code was prepared in V11 of Dyalog.

⍝ Version 1.1 from 2006-12-22 ⋄ Kai Jaeger ⋄ APL Team Ltd
 (⎕ML ⎕IO)←1
⍝ Create a reference to the "CURRENT_USER" part of the Windows registry 
⍝ using "CurrentUsers" within "Microsoft.Win32.Registry":
⍝ Note the "CurrentUser" is a field, not a method!
⍝ This is VERY important because no right argument is needed!!
⍝ The same thing with "Test9999a" using a sligtly different technique:
⍝ "Close" it
⍝ To specify the default value, specify an empty vector as key name:
 test9999RegKey.SetValue'' 'Here the default is saved!'
⍝ Get the default value of a Registry Key:
⍝ Create a SubKey:
⍝ Create another SubKey:
⍝ List all SubKeys:
 ⎕←test9999RegKey.GetSubKeyNames ⍬
⍝ Create data for the TestSettings subkey
 testSettings.SetValue'Language' 'French' ⍝ String
 testSettings.SetValue'val_1' ¯127        ⍝ String
 testSettings.SetValue'val_2' ¯128        ⍝ String
 testSettings.SetValue'val_3' 1234.56     ⍝ String
 testSettings.SetValue'val_4' 0           ⍝ String
 testSettings.SetValue'val_5' 1           ⍝ String
 testSettings.SetValue'val_6' 128         ⍝ String
⍝ BUT:
 testSettings.SetValue'val_7' 10          ⍝ DWORD
 testSettings.SetValue'val_8' 127         ⍝ DWORD
⍝ Request the type for a string
⍝ Request the type for a DWORD
 :Trap 90
     ⎕←'"Unknown" does not exist!'
⍝ Get a particular value:
 ⎕←1+⍎testSettings.GetValue⊂'Val_5' ⍝ Key is not case sensitive!
 ⎕←1+testSettings.GetValue⊂'val_6'  ⍝ This is an integer
⍝ Get an unkown value with a specified default value ¯1:
 ⎕←testSettings.GetValue'Unknown' ¯1
⍝ Again with a string as default
 ⎕←testSettings.GetValue'Unknown' 'This key is unknown'
⍝ Get names of all keys of a subkey
⍝ ****** Available only in .NET version 2.0 and better ******
⍝ Let's use "GetValue" which is available as a
⍝ shared method of the "Registry" class:
 path←'HKEY_CURRENT_USER\Software\Dyadic\Dyalog APL/W 11.0'
 ⎕←Microsoft.Win32.Registry.GetValue path valName buff
⍝ ****** END .NET version 2.0 ******
⍝ Delete a particular Value
⍝ Delete tree (SubKey and all of it's values)
⍝ Trying to delete a non-existing thing throws an exception:
 :Trap 90
⍝ Delete the top entries we have just created:
 regKeyObj.DeleteSubKey∘⊂¨'Test9999' 'Test9999a'
⍝ Close all references
 (testSettings test9999aRegKey test9999RegKey).Close
⍝ End

Author: KaiJaeger

CategoryDotNet - CategoryDyalogDotNet - CategoryDyalogExamplesDotNet

RegistryInfo (last edited 2015-04-05 01:24:18 by PierreGilbert)