2

I have a Windows Registry file (.REG), which is entered into the Registry when being double clicked.

Now I want to achieve the same result in code with C#. Is there a tool which could convert the REG file into valid C# code doing the same?

I know I could simply keep the REG file and run regedit /s <file>.reg, so it's basically a one-liner. The point is that I need to adapt the code so it does slightly different things in different circumstances. Basically I want my application to do it, not with Regedit.

It should:

  • open Registry keys for writing
  • create keys
  • create REG_DWORD, REG_SZ, REG_EXPAND_SZ
  • put the objects into using() constructs
  • support Registry deletion syntax
  • ideally writes "clean" code, i.e. introduces variables for long substrings

It would be nice if it's a Visual Studio plugin, but any other solution is probably ok, too, because it will only be used once per REG file.

I have tried:

  • reg-to-csharp, but it cannot deal with REG_DWORD and REG_EXPAND_SZ, does not dispose the objects, creates subkeys instead of values, does not support delete syntax
  • reg-to-csharp makes a few fixes, but still has no REG_EXPAND_SZ support, does not dispose objects nor support delete syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.