R – File Security on Windows Vista with .NET Installer

file-permissionsinstallationnetwindows-vista

I am trying to write an installer (by creating a .vdproj) that will work on both Windows Vista and XP. The only thing I am finding is that when I try to run it on Vista, the files that I include in the installer are installed with Read-only permissions for the Users groups. This is a problem because the application needs to read/write from these files. The only way I have been able to get it to work is to either "Run as Administrator" or actually change the permissions. Does anyone know how to make these files be open to anyone to write? Thanks.

Best Answer

The Program Files folder and it's contents are read only for standard users. This is by design, and you'll find that this is the case on Windows XP as well. It's just that on windows xp, so many people run with administrator rights all the time that you might get away with it. If you ever want to distribute your app into a business environment, you'll soon find that it won't work on XP there, either.

The solution is to NOT place files in the program's executable folder if standard users will need write access. Put them in the Application Data folder instead. For most xp machines, that will be here:
C:\Documents And Settings\All Users\Application Data\Your App

However, that won't always be the case and it's a little different on Vista anyway, so make sure you get that path via the mechanism provided by your programming environment. In .Net, you can use the Environment.GetFolderPath() function.