Results 1 to 8 of 8

Thread: How do I create a settings file for my project?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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.

  2. #2
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    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

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: How do I create a settings file for my project?

    Have you considered using the my.settings object?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Re: How do I create a settings file for my project?

    Quote Originally Posted by ident View Post
    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.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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
  •  



Click Here to Expand Forum to Full Width