Differences between revisions 3 and 4
Revision 3 as of 2006-12-31 21:24:47
Size: 3895
Editor: KaiJaeger
Comment:
Revision 4 as of 2007-01-03 09:14:14
Size: 3900
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
{{{ Microsoft∆Win32∆Registry;⎕ML;⎕IO;subKeyRef;test9999RegKey;regKeyObj;test9999aRegKey;path;valName;buff;val;testSettings {{{   Microsoft∆Win32∆Registry;⎕ML;⎕IO;subKeyRef;test9999RegKey;regKeyObj;test9999aRegKey;path;valName;buff;val;testSettings
Line 8: Line 9:

⎕ML ⎕IO←1
 (⎕ML ⎕IO)←1
Line 11: Line 11:

⍝ Create a reference to the "CURRENT_USER" part of the Windows registry using
the static method "Users" within "Microsoft.Win32.Registry":
⍝ Note the "CurrentUser" is a field, not a method: no right argument needed:
⍝ 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 i
mportant because no right argument is needed!!
Line 17: Line 17:
Line 20: Line 19:

⍝ "Close" does
⍝ "Close" it
Line 23: Line 21:
Line 26: Line 23:
Line 29: Line 25:
Line 32: Line 27:
Line 35: Line 29:
Line 38: Line 31:
Line 47: Line 39:
Line 51: Line 42:

⍝ Request type for a string
⍝ Request the type for a string
Line 54: Line 44:

⍝ Request type for a DWORD
⍝ Request the type for a DWORD
Line 62: Line 51:
Line 67: Line 55:
Line 70: Line 57:
Line 73: Line 59:

⍝ Get names of all keys:
⍝ Get names of all keys of a subkey
Line 77: Line 62:
Line 79: Line 63:
First we will use "GetValue" which is available as a Let's use "GetValue" which is available as a
Line 84: Line 68:
 val←Microsoft.Win32.Registry.GetValue path valName buff  ←Microsoft.Win32.Registry.GetValue path valName buff
Line 86: Line 70:
Line 89: Line 72:
Line 92: Line 74:

Deleting a non-existing things throws an exception:
Trying to delete a non-existing thing throws an exception:
Line 100: Line 81:

⍝ Delete the top entries we've just created:
⍝ Delete the top entries we have just created:
Line 103: Line 83:
Line 106: Line 85:

Dealing with the Windows Registry

Both, the Registry class as well as the 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.

 Microsoft∆Win32∆Registry;⎕ML;⎕IO;subKeyRef;test9999RegKey;regKeyObj;test9999aRegKey;path;valName;buff;val;testSettings
⍝ Version 1.1 from 2006-12-22 ⋄ Kai Jaeger ⋄ APL Team Ltd
 (⎕ML ⎕IO)←1
 ⎕USING,←⊂''
⍝ 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!!
 regKeyObj←Microsoft.Win32.Registry.CurrentUser
 test9999RegKey←regKeyObj.CreateSubKey⊂'Test9999'
⍝ The same thing with "Test9999a" using a sligtly different technique:
 test9999aRegKey←Microsoft.Win32.Registry.CurrentUser.CreateSubKey⊂'Test9999a'
⍝ "Close" it
 test9999aRegKey.Close
⍝ 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:
 ⎕←test9999RegKey.GetValue⊂''
⍝ Create a SubKey:
 {}test9999RegKey.CreateSubKey⊂'Misc'
⍝ Create another SubKey:
 testSettings←test9999RegKey.CreateSubKey⊂'TestSettings'
⍝ 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
 ⎕←testSettings.GetValueKind⊂'Language'
⍝ Request the type for a DWORD
 ⎕←testSettings.GetValueKind⊂'val_6'
 :Trap 90
     ⎕←testSettings.GetValueKind⊂'Unknown'
 :Else
     ⎕←'"Unknown" does not exist!'
 :EndTrap
⍝ Get a particular value:
 ⎕←testSettings.GetValue⊂'Language'
 ⎕←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
 ⎕←testSettings.GetValueNames
 testSettings.GetValueNames,[1.5]⎕←testSettings∘{⍺.GetValue⊂⍵}¨testSettings.GetValueNames
⍝ ****** 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'
 valName←'wssize'
 buff←System.Object
 ⎕←Microsoft.Win32.Registry.GetValue path valName buff
⍝ ****** END .NET version 2.0 ******
⍝ Delete a particular Value
 testSettings.DeleteValue⊂'val_8'
⍝ Delete tree (SubKey and all of it's values)
 test9999RegKey.DeleteSubKeyTree⊂'TestSettings'
⍝ Trying to delete a non-existing thing throws an exception:
 :Trap 90
     test9999RegKey.DeleteSubKeyTree⊂'DoesNotExist'
 :Else
     ⎕←⎕DM
 :EndTrap
 test9999RegKey.DeleteSubKey⊂'Misc'
⍝ Delete the top entries we have just created:
 regKeyObj.DeleteSubKey∘⊂¨'Test9999' 'Test9999a'
⍝ Close all references
 (testSettings test9999aRegKey test9999RegKey).Close
⍝ End

Author: KaiJaeger

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