Creating Folders in Registry - VB2005

  • 14 years ago

    Hey guys,

    VB .NET does appear to be much easier to access and modify the registry, but I am stuck on one problem.  I can access the regisrty, create a new key, and assign a value.  However, I can only do this if the folder already exist.  How do I create a new folder? 

    For example, the below code will run with no errors, but upon checking the registry a key has not been added.  If I change 'MyProgram' in the .CreateSubKey line to a folder that already exist in the the registry, then a key is made under that folder with the proper value.  So how do I force the code to make a folder if it does not exist?

    Thanks,
    /Tril

    Imports Microsoft.Win32  ‘Namespace Required for Accessing Registry

    Public Sub WriteToRegistry



    Dim regKey As RegistryKey, regSubKey As RegistryKey
    ‘regKey now points to HKEYCURRENTUSER Registry Key
    regKey = Registry.CurrentUser
    ‘A Sub key called MyProgram is created under the HKEYCURRENTUSER key
    regSubKey =regKey.CreateSubKey ("MyProgram")
    ‘The value of the Key is set to VeryGoodSetting
    regSubKey.SetValue ("MyValue", "VeryGoodSetting")
    End Sub

















  • 14 years ago

    Meh... added this one line and it seems to work now.

    regKey.Flush()



Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”