VB.NET 2015+ Best place to save application scope data

In VB.NET, where is the best place to save application scope data?  I am looking to save one or more data files to be used to persist application-level settings and configurations between different users.

This doesn't seem to work as each user as Windows seems to call up their own virtual copy of the file.
      Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

My.Settings only works for user-scope settings.  The application-scope settings get reset when the application is reloaded ... i.e. the data doesn't persist.
eeyoAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
That's the right way to get the Roaming folder, but for Application data I'd suggest using a different location:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

Here's an article that lists all the SpecialFolders available:

https://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.110).aspx
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
There are Application level settings, but those are typically set at design or deployment, and a standard user would not be able to change/add to those because of UAC. .NET offers the ConfigurationManager, but you're liable to run into the same issue with UAC.

You can always use the registry to store those, but you may also run into UAC issues with that as well.

You can resort to the old INI file approach, or something similar. I use an XML file stored in the Roaming\<NameOfMyProgram>, which seems to work fine.
0
 
eeyoAuthor Commented:
Would this be the appropriate path for the "Roaming" folder (+\ + NameOfMyProgram)?
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Open in new window

gives me C:\Users\<user name>\AppData\Roaming but that folder and the files within it would be different if another user logged in.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
eeyoAuthor Commented:
I figured out what one of my problems was.  I was using ClickOnce which uses a strange virtualized folder.  I went through the ordeal of figuring out that I needed to download the Visual Studio Installer (doesn't come standard).  I will try to tinker with it more now ...
0
 
eeyoAuthor Commented:
So, I just tried using Environment.SpecialFolder.CommonApplicationData (C:\ProgramData\ in Win 10).  Reading and writing files there are fine if you are an admin user, but if you log in as a standard user, you will get an access denied error.  Any other thoughts?

I even tried adding a custom "MyConfig.xml" file to the Project (selecting "Copy to Output Directory"), which means it installs in the startup directory.  Even the admin user that installed the application can't write to this custom file.

Any other thoughts?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Only other thing I could suggest would be either (a) a database or (b) a Public Document folder for your xml file.
0
 
eeyoAuthor Commented:
Any thoughts about these possibilities:

1) Using the good old Windows Registry?  Is there a reason why it has fallen out of favor?  In this case, I might have to dump an XML file into one of the registry keys.  Is there a max string length for registry keys?
2) Creating a Resource file (Project menu -> Properties -> Resources tab -> Add Resource -> Add Existing File) such as a .txt or .xml file, then editing this resource file at runtime?  Hopefully this would allow any user (including windows "Standard Users") to edit this resource file.  I tried to implement this but couldn't figure out how.
0
 
eeyoAuthor Commented:
You can resort to the old INI file approach, or something similar. I use an XML file stored in the Roaming\<NameOfMyProgram>, which seems to work fine.
Scott, was this for user or application scope data?
0
 
eeyoAuthor Commented:
While there is no perfect solution to this, this may be the best one for now:
Environment.SpecialFolder.CommonApplicationData (C:\ProgramData\ in Win 10)
It still requires the user to have admin rights, unfortunately.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.