-
Mar 28th, 2014, 12:37 PM
#1
Thread Starter
Addicted Member
How do I create a settings file for my project?
Hello everyone,
I have a question that I searched on the internet but I couldn't find an answer. I have a project that is installing in Program Files and I have a text file in that folder that I am using as a settings file.
I am also using this file to remember what was the state of my project when it was closed so that when i open it again it remembers the users choices and starts at the same point that it was when it got closed.
Now, this works fine in windows XP. In Windows 7 it works only if I am opening "As administrator" but I was wondering what is the best approach to use this file? Where else should I create it? In windows 7 I get no error but the file is simply not modified at all.
As far as I have read it is not recommended to write to files in system folders. How else can I store that data?
Thx.
-
Mar 28th, 2014, 01:25 PM
#2
Hyperactive Member
Re: How do I create a settings file for my project?
Most programs use 1 of the folders from this location %userprofile%\AppData
because this location doesn't require authentication to read/write data unlike the program files folder.
You could also make it so your program always is run as admin
You can do the following to make sure the program has admin permissions:
You can edit the UAC Settings (in VB 2008) which is located in the Project Settings. Look for the line that says
Change level="asInvoker" to:
level="asInvoker" (normal account - default)
level="requireAdministrator (require administrator - What you need... but could be next one)
level="highestAvailable" (if anything is higher then administrator, require that)
Hope it helps
-nfell2009
-
Mar 28th, 2014, 01:32 PM
#3
Re: How do I create a settings file for my project?
Have you considered using the my.settings object?
-
Mar 28th, 2014, 01:37 PM
#4
Thread Starter
Addicted Member
Re: How do I create a settings file for my project?
That works. Thx a lot. It's just what I needed. I just edited the Windows Setting located in the Project Settings and it works fine.
What about my.settings? Is there another way?
Cheers.
-
Mar 28th, 2014, 01:41 PM
#5
Re: How do I create a settings file for my project?
What is it exactly you are wishing to save the state of. Please provide a full and clear description.
-
Mar 28th, 2014, 01:50 PM
#6
Thread Starter
Addicted Member
Re: How do I create a settings file for my project?
Originally Posted by ident
What is it exactly you are wishing to save the state of. Please provide a full and clear description.
It's just a text file where I am writing some info. For example I have some projects organized by year. If a user selects a year and a project from that year, then I want my app to start at that point. Meaning the last year and last project.
So, when the app closes I am just writing the year and project name in a text file that I am reading at the next opening and automatically going to that selection.
-
Mar 28th, 2014, 01:58 PM
#7
Re: How do I create a settings file for my project?
My.Settings was added to get around the need to do what you are doing. You can go into the Project|Properties menu item and go to the Settings tab. Add whatever settings you want to that and give them types. Those settings become pretty much like variables in your program in that you can access them in code with:
My.Settings.YourSettingNameHere
They even have the right types. You don't have to worry about opening/closing files or any of that nonsense. You don't even have to worry about saving My.Settings, normally, since they are saved automatically (though I think you can disable that if you have a mind to). Also, they are part of the program, so you don't have to deal with passing some extra file around.
The one thing that you have to be aware of is that they are saved as XML, which means that they are essentially plain text, and can be accessed/edited with any text editor by a person who knows what they are doing. If that is an issue then you'd have to be sure to encrypt them, but that can be done, as well.
One thing that I have done, on a slightly related note, was that I have a class that holds a whole bunch of settings for an application (it holds a theme, actually, which sets lots of appearance items). I added a string type of setting and serialize the class to a Base64 encoded string, which I store in My.Settings. Pretty convenient, really.
My usual boring signature: Nothing
-
Mar 28th, 2014, 02:13 PM
#8
Thread Starter
Addicted Member
Re: How do I create a settings file for my project?
Ok, that sound even better. I will try and modify my app this way and see how it works. Thx.
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
|