R – How to update a VB6 app from XP to Vista

uacvb6windows-appcompat-platformwindows-vista

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.

Best Answer

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.