|
-
May 25th, 2004, 03:30 PM
#1
Thread Starter
Lively Member
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.
-
May 26th, 2004, 04:36 AM
#2
Member
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.
-
May 26th, 2004, 06:31 AM
#3
Thread Starter
Lively Member
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.
-
May 26th, 2004, 07:18 AM
#4
Hyperactive Member
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:
'Add these to Imports
Imports Microsoft.Win32
Dim softKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
Dim myAppKey As RegistryKey = softKey.CreateSubKey("MyApp") 'Creates or opens a key, so you can rely on it to
'always return the key to your app
myAppKey.SetValue("Winpos", "10,100")
myAppKey.SetValue("Winsize", "2500,5000")
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.
-
May 26th, 2004, 07:29 AM
#5
Thread Starter
Lively Member
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...
-
May 26th, 2004, 08:26 AM
#6
Hyperactive Member
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.
-
May 26th, 2004, 08:30 AM
#7
Thread Starter
Lively Member
ehmm... no C# knowledge... send the howto anyway, i'll take a look.
thanks.
-
May 26th, 2004, 09:00 AM
#8
-
May 26th, 2004, 09:03 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|