views:

715

answers:

4

I work on a vb6 application which is having problems with Vista, for the obvious reasons (writing to program files, and other things that are no longer allowed by default).

  • Where should I store application data or user's saved files?
  • Do I need priviledges to create folders and files, there, too?
  • What other common actions will cause problems?
  • The program has an updater which must download and register files, how do I elevate priviledges when this occurs?

Some of these questions have obvious answers, but I want to get the obvious stuff right.

A: 

In the sort term turning off UAC and installing the ActiveX installer server will help. Long term you need to put data and configuration information in the users directory under \users or in \programdata.

Jim Blizard
A: 

In the short run it might not be necessary at all to modify your application, because Vista comes with a set of compatibility options to allow legacy applications to run. This includes file and registry virtualization, a feature which basically redirects write operations to protected folders such as C:\Program Files to a virtual location only visible for the specific application running in a compatibility mode.

Some more details are mentioned in this article: How To Manage Windows Vista Application Compatibility in Dr. Dobb's.

0xA3
It sounds like compatibility should be automatic, but we are getting real complaints about compatibility issues. Reading program settings from a file in program files seems to be throwing an error.
Strilanc
That's surprising, because reading a file should always be possible. Are you sure that the file is opened in read-only mode by your application?
0xA3
The way the app opens the file is a bit weird. The app functionality is spread over multiple DLLs [to make updates smaller and encapsulate some stuff]. Because file-numbers don't cross DLLs, one DLL opens and reads files. The file is opened as 'binary', which is read/write.
Strilanc
Another note: because the DLLs have different application paths, we always use the fully qualified file path. "C:\program files\program\file.dat" instead of "file.dat"
Strilanc
+3  A: 

Depending upon what you are doing, you might be in for a world of pain. There are no hard and fast answers to any of those questions, but from someone who is going through the same issues right now, here's what I know.

1) Where should I store application data or user's saved files?

This depends on what you are wanting to do. If you want them per user, store them in Users/AppData, if you want them for all users, store them in Common/AppData

  If SHGetFolderPath(0, CSIDL_COMMON_APPDATA, -1, SHGFP_TYPE_CURRENT, sTempPath) = 0 Then
      sCommonAppdata = Left$(sTempPath, InStr(1, sTempPath, Chr(0)) - 1) &  "CompanyName\AppName"
  End If

Change that to CSIDL_APPDATA for the Users AppData directory. Note: These map to totally different places on the filesystem for XP and Vista so when you are debugging prepare to look in different places.

2) Do I need priviledges to create folders and files, there, too?

You need Adminsitrator access to write anything in Program Files, if at all possible don't do it! We are currently running into issues that the API's for VB and the standard API's behave differently on files in Program Files.

3) What other common actions will cause problems?

There are lots of hidden gotchas. Just to name a few, you cannot communicate through IPC or Named Pipes to other applications (we have a Service that we were talking to through a Tray Notification Icon and that had to be completely re-written). Anything were you see a UAC notification is very difficult. Also you cannot write to anything in the Registry in LOCAL_MACHINE without Administrator, so you either have to stick to LOCAL_USER or raise credentials (see below).

4) The program has an updater which must download and register files, how do I elevate priviledges (sic) when this occurs?

Good luck with this, I highly recommend that you don't write it in VB6, like I said, the VB6 file api's appear to access files differently from the standard API's. If you need to elevate privileges see this post that someone kindly helped me with.

Kris Erickson
According to one of the articles in the other answers, your phantom folder is at C:\Virtual Store\SID\Program Files\...
Strilanc
If you wrote a program in C and made the same mistakes your program "using standard APIs" would see the same behavior. This is not a VB6 issue but a failure to declare the program Vista aware.It is all about the filesystem virtualization appcompat shim being applied to a legacy program. This was documented for developers well before Vista was released.
Bob
A: 

Karl Peterson wrote a nice article on where to store user data & app data, with a VB6 class that retrieves the location of the special paths for you.

MarkJ