Pergunta

I maintain a VB6 application that stores its data (access files) in a subfolder of the application folder. So, when the user installs the application to the default location of C:\Program Files\MyApp the data ends up in the Virtual Store. I have now been given the sweet task of converting the 1000 or so App.Path statements to a path to a Data folder that will not have any security issues. Can someone please help me out by pointing the way to some resources that will spoonfeed to me how to handle data in the Users\< Username>\AppData\Local\ folder?
Should I use the local AppData folder, or can I have the user choose a suitable location?

Foi útil?

Solução 3

A useful discussion can be found here

Outras dicas

Well if we assume a couple of things:

  • This is only an issue for Vista or later.
  • Your data is in subfolders, under App.Path.

... I have a sort of workaround that might be used.

Note that I only use this trick when I have a bunch of old VB6 programs that were written to use data in folders beneath App.Path, sort of a quick and dirty hack to get a lot of programs working quickly. I almost always add or update the application manifest as well, mostly to prevent virtualization.


The changes I make are:

  • Add a little code to Sub Main (inserting a Sub Main if the program doesn't already have one).
  • Add two Class modules (invoked by the new Sub Main code) to the project.

When the new program is deployed, on Vista or later the program needs to be run once as administrator. In the newest version of my add-in code the program will prompt the user to rerun it elevated if required, and when OKed it does so and self-terminates.

After the first run everything should be hunky-dory, running much as it did under Win2K, XP, etc.


This startup code that requires elevation provides a list of the App.Path subfolders required to the PathLinks class.

Pathlinks creates a program folder under the Public special folder, then creates matching subfolders for the data under that. Next it moves any files and subfolders in these App.Path subfolders into the new locations. Finally it creates symlinks to the new folders back under App.Path.

If running under Windows prior to Vista, PathLinks merely creates any of the list of App.Path subfolders (under App.Path) that don't already exist (i.e. by installation).

From here on the program will find the files in the new location, without needing any changes to its use of App.Path at all.


One of the two add-in Classes is cosmetic and you can remove it. It just lets the startup code invoke TaskDialog instead of using a MsgBox call.

Be sure to scroll down for the newest version posted at PathLinks - Tame App.Path Under Vista+

Note that the sample project skips running the application when it does that "first time elevated" trick. It just does an Exit Sub in Sub Main after relocating data and symlinking to it.

I would use the local AppData folder:

Dim sAppData As String

sAppData = Environ("USERPROFILE") & "\AppData"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top