Results 1 to 10 of 10

Thread: Best method to store application settings in VB .net

  1. #1

    Thread Starter
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,159

    Best method to store application settings in VB .net

    I have an application that I want to modify to remove storing settings that can change in the application code and move them to a simple text file that can be changed without recompiling the program. I have looked into storing them in My.Settings, however, I do not want them saved in a location that is in any specific user's profile. Users of the application will be different on the same computer where this application is used, and the stored settings need to be the same for all users. In addition, users will not have any access to each other's files or settings. There does not seem to be a way to specify a place to store the My.Settings values, so it looks like I will need to create my own method for this. If anyone has any other ideas or information on My.Settings storage that might be useful, ideas would be appreciated. It is also worth mentioning that the settings would be in the form of 2 tables, as shown below:

    Code:
    Locations:
    Active     Location#1
    Inactive   Location#2
    
    Users:
    Active     UserID#1   User#1   UserName#1
    Inactive   UserID#2   User#2   UserName#2
    Also worth noting is that the file has to be editable by people using Notepad, if necessary. I have an Excel file that can be used to generate the table files in any format needed, but I do not want to use a database, since users that may have to change the tables in the future may not have any idea how to alter a database or have any access to any software that could be used for that purpose. They will not have rights to install software on the computers.
    Last edited by jdc2000; Sep 26th, 2022 at 12:27 PM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,970

    Re: Best method to store application settings in VB .net

    Application settings in .NET have two scopes: Application and User.
    Settings that are Application in scope will apply to all users of the application. They are tied to that application, not any users. As a result, they are also read-only, which means you set them at design time, and that's what their values will be at run-time. It's stored in the application.exe.config file along side the application when it is deployed.

    Settings that are User in scope however will only apply to the current Windows user of the application. It can be stored optionally in their roming profile, or in their local profile. They are also read/write in nature.

    So if you have settings you want on the machine, but not have user-specific ones, then application scope settings is what you're after.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,970

    Re: Best method to store application settings in VB .net

    Also look up Custom Configurations in .NET ... there's a way to store config files that are separate and independent of application or user config files. I remeember doing it once... but it was a long long time ago and I don't remember any specifics, other than it meant creating a ConfigurationManager class and then you can control what is loaded/saved from where.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,159

    Re: Best method to store application settings in VB .net

    Application settings might be an option, as long as the settings file that is used is located in the same folder as the .exe file. These applications are designed so that the users do not need to install anything other than the .Net Framework (already installed), since they do not have rights to install any software. The only issue would be the method of storing the settings, since I actually have 2 tables rather than individual settings. The settings file would have to be editable with Notepad and/or Excel or other method so that changes to the settings could be made. I do not plan to have the actual applications have forms for editing the settings, since the users should not be changing those themselves. I will look into doing this to see if there are any other issues. The alternative is just to use some simply text files that are located in the same folder as the application .exe file.

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,970

    Re: Best method to store application settings in VB .net

    The config file is a plain text file in XML format ... easily editable with notepad or something.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Addicted Member
    Join Date
    Jan 2013
    Posts
    143

    Re: Best method to store application settings in VB .net

    Quote Originally Posted by jdc2000 View Post
    since the users should not be changing those themselves
    Then do what a PE does; store the settings in an encrypted form in a text file and put it in a public place (such as the same folder where the exe is). Your program will have to read the text, decrypt it, and then proceed accordingly. This way everyone has access to the text file but no one can change it in any meaningful way. You could implement the encrypting routines in your application or you could create a separate application that only you has access to it to encrypt/save the settings as a text file.

  7. #7

    Thread Starter
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,159

    Re: Best method to store application settings in VB .net

    Encryption should not be needed. The average user of this application will not even know that the settings file exists, much less how to change it. The application will validate any settings in the file before use, and discard any that do not conform to specifications.

    The only issue will be to convert each table to a string value that can be stored. This might be an issue, since at present for the Locations I have about 220 values with a total of about 3000 characters total for all of the values. From what I have seen, that should not be a problem, although it would be more of a pain to edit the settings file with Notepad. However, I plan on using a custom Excel workbook to edit and validate the field values, and then export them to the settings file, so that should eliminate that issue for the user(s) that will maintain the lists.

  8. #8
    Banned
    Join Date
    Sep 2022
    Posts
    16

    Re: Best method to store application settings in VB .net

    You can use the My.Settings.Save method to persist changes to the user settings.
    Typically, applications are designed to persist the changes to the user settings when the application shuts down. This is because saving the settings can take, depending on several factors, several seconds.

  9. #9
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,698

    Re: Best method to store application settings in VB .net

    Encryption should not be needed. The average user of this application will not even know that the settings file exists, much less how to change it.
    Security by obscurity...what could go wrong with that
    Please remember next time...elections matter!

  10. #10

    Thread Starter
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,159

    Re: Best method to store application settings in VB .net

    Security by obscurity...what could go wrong with that?
    Not much. The worst that could happen is that the user that messed up the settings and did not test them before heading out into the field to use the program would find that they had to go back to their office, or at least back into a cell phone service area, to get help on fixing them before they could perform their tasks. This program is used on laptop computers that do not connect to any network.
    Last edited by Shaggy Hiker; Oct 5th, 2022 at 03:40 PM. Reason: Fixed QUOTE tag.

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