Skip to main content

How to delete an entry from the registry in .NET COBOL?

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

How to delete an entry from the registry in .NET COBOL?

What classes to be used to access and delete information in the Windows registry from a COBOL .NET application?

Resolution:

There are classes for manipulation of Registry information in the Microsoft.Win32 namespace.

Some example code that uses these classes to insert and remove information in the Registry is:

      $set sourceformat"variable"

       program-id. RegDemo as "RegDemo.RegDemo".

       environment division.

       configuration section.

       repository.

           class cRegistry as "Microsoft.Win32.Registry"

           class cRegistryValueType as "Microsoft.Win32.RegistryValueKind"

           class cRegistryKey as "Microsoft.Win32.RegistryKey"

           class cString   as "System.String"

           class cObject   as "System.Object"

           .

       

       data division.

       working-storage section.

       01  userRoot     string value "HKEY_CURRENT_USER".

       01  subkey       string value "RegistrySetValueExample".

       01  keyName      string.

       

       01  RegKey       cRegistryKey.

       01  RegCurrentUserKey cRegistryKey.      

       01  DWORDValue   binary-long.

       01  StrValue     string.

       

       procedure division.

           

           set keyname to cString::"Concat"(userRoot,"\\",subkey)

           

           invoke cRegistry::"SetValue"(keyname,"DWORDItem",1234,cRegistryValueType::"DWord")

           invoke cRegistry::"SetValue"(keyname,"StringItem","This is a Test",cRegistryValueType::"String")

           

           display "Stored Data in Registry -  Now Read Back"

       

           set DWORDValue to cRegistry::"GetValue"(keyname,"DWORDItem",0) as binary-long

           

           display "   DWORD=" DWORDValue

           

           set StrValue to cRegistry::"GetValue"(keyname,"StringItem","Default")

           

           display "   string=" StrValue

           

        *>   invoke cRegistry::"CurrentUser"::

           set RegCurrentUserKey to cRegistry::"CurrentUser"

           set RegKey to  RegCurrentUserKey::"OpenSubKey"("RegistrySetValueExample")

           invoke RegCurrentUserKey::"DeleteSubKey"("RegistrySetValueExample")

       

        *> Could also use this to get rid of multiple levels    

        *> invoke RegCurrentUserKey::"DeleteSubKeyTree"("RegistrySetValueExample")

           

           goback.

       end program RegDemo.

A working Visual Studio solution is attached to this article.

Attachments:

RegDemo.zip

Old KB# 4403