Fail if the ‘shell’ key hasn’t already been created.

Summary

Id: 5247.1
Type: Bug Bug
Current Status: Open

Detail

2 Aug 2003 Open Alex Zupancich

I happened across a couple of minor bug that you might like to update in your next revision of the article:

In the ClassAssociations.cs file:

public void Save(){ RegistryKey rootKey = getRootKey(); RegistryKey items = rootKey.OpenSubKey(SubKeyName); RegistryKey shell = items.OpenSubKey("shell", true); if ((shell == null) && (this.InnerList.Count > 0)) { // need to create the key shell = rootKey.CreateSubKey("shell"); if (shell == null) { .......

If you do not have the shell key in your registry the above code will fail:

in this case, HKLM\SOFTWARE\Classes\* is opened as a ReadOnly key (bug #1) and later you try to create the 'shell' key in the RegistryKey object rootKey (HKLM\SOFTWARE\Classes) when it should be created in items (HKLM\SOFTWARE\Classes\*)

Code changes should be as follows:

public void Save(){ RegistryKey rootKey = getRootKey(); RegistryKey items = rootKey.OpenSubKey(SubKeyName, true); RegistryKey shell = items.OpenSubKey("shell", true); if ((shell == null) && (this.InnerList.Count > 0)) { // need to create the key shell = items.CreateSubKey("shell"); if (shell == null) { .......