Results 1 to 9 of 9

Thread: Using Registry to store Appplication Settings.

  1. #1

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64

    Using Registry to store Appplication Settings.

    Hello there,
    i need some hints on storing my application settings in the registry.
    i want to create a registry Key: "HKEY_LOCAL_MACHINE\SOFTWARE\Myapp\"
    and store different subkeys in it, like "Winpos" , "Winsize", "AppPath", etc

    And i would also like to know how to read and use them after storing.

    Thanks.
    ehmm...

  2. #2
    Member
    Join Date
    Aug 2003
    Posts
    51

    Re: Using Registry to store Appplication Settings.

    Originally posted by mindloop
    Hello there,
    i need some hints on storing my application settings in the registry.
    i want to create a registry Key: "HKEY_LOCAL_MACHINE\SOFTWARE\Myapp\"
    and store different subkeys in it, like "Winpos" , "Winsize", "AppPath", etc

    And i would also like to know how to read and use them after storing.

    Thanks.
    Why don't you just using a simple text file method.

  3. #3

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    just because i decided to use registry settings like most applications do. i use text file right now, but i don't want the settings to be transparent to the user. obfuscating the settings file might be a sollution, but i just want to know how to use the registry, i think it's a must for a serious application developer.
    ehmm...

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    A strong point to consider when leaning in the direction of using the Registry to store settings on a users workstation is Security.
    Back in the days of com, software usually had more rights on the machine than the user actually logged in working. With .NET, this has all changed. Because of the way the framework implements security, your app has no more rights than the person currently logged into the machine. So if Joe User cannot open the registry editor, then neither can your app.
    Having said that, I actually prefer to use the registry when I can, but I have worked in several corporate environments where the sys admins had the workstations locked down tighter than a gnats a$$. I was forced to use xml configuration files and I find them as easy to use as the registry. by importing System.Security.Cryptography, you can suitably encrypt/obfuscate your config file so that the user only sees encrypted information if they open it.
    Now if after all this you still want to use the registry then here's how to do it.

    VB Code:
    1. 'Add these to Imports
    2. Imports Microsoft.Win32
    3.  
    4. Dim softKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
    5. Dim myAppKey As RegistryKey = softKey.CreateSubKey("MyApp") 'Creates or opens a key, so you can rely on it to
    6.                                                               'always return the key to your app
    7. myAppKey.SetValue("Winpos", "10,100")
    8. myAppKey.SetValue("Winsize", "2500,5000")
    9. myAppKey.SetValue("AppPath", "C:\Program Files\MyApp")
    I have tested this code on my machine and it works as expected.
    I hope this short tutorial helps you in your efforts, but with the .NET framework it is always critical that you know the environment to which you are deploying for security purposes.
    Last edited by CyberHawke; May 26th, 2004 at 07:22 AM.

  5. #5

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    Cyberhawke thanks a lot for the precise answer. now that i saw the cons of the registry method , i'm not so sure i'd like to use it anymore.
    I understand the registry better now but i think i would like to know more about the xml settings file. How would i use one, say, for the same example (apppath, winpos, winsize).
    Thanks again.
    Last edited by mindloop; May 26th, 2004 at 07:50 AM.
    ehmm...

  6. #6
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    How are your C# skills?
    I have a how-to app that explains how to access a config file but it's in C# and I don't have time to rewrite it for VB.

  7. #7

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    ehmm... no C# knowledge... send the howto anyway, i'll take a look.
    thanks.
    ehmm...

  8. #8
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Ok, you're in luck, it turns out that I have the same project for VB, btw, I strongly recommend to you and anyone that reads these forums to check out the samples on MSDN. That is where this code originates.
    Something like (101 VB.NET Samples) on MSDN
    I actually converted this code to VB6, for use in apps where registry access on the workstation was suspect
    Attached Files Attached Files

  9. #9
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Don't use the registry, more and more apps these days are using serialization to store a central Settings class to a file. All my apps do this because there is a hell of a lot o data to load, plus it speeds up loading time.

    And the registry isn't strict enough.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width