Rohit R Keyan
Rohit R Keyan

Reputation: 1

Windows 7 Compatibility Issue in .NET

When we create a SetUp & Deployment project for our application in .net, the default folder for our application to be installed is being set as C:\Program Files..... Our application will run perfectly if we are using a Windows XP machine. But if we are using a Windows Vista or Windows 7 machine, the application wont run perfectly, especially if we are performing any file operations in our application...

Can anyone find a solution for this problem? Is there any means to penetrate this User Account Control and File Access Controls of Windows 7? or can any1 give a choice to change the default installation folder from [ProgramFilesFolder]\[Manufacturer]\[ProductName] to some other folder?

Upvotes: 0

Views: 631

Answers (5)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

I'd suggest start here http://channel9.msdn.com/pdc2008/PC51/

That will give you a good foundation.

Upvotes: 0

slugster
slugster

Reputation: 49984

First of all, you should not set your app to install under C:\Program Files\..., you should instead set it to %PROGRAMFILES%\... While these will usually equate to the same thing, they can be different on a 64 bit system, or they can be wildly different if the system has been set that way.

As already mentioned, don't try to circumvent the UAC, it is there for a reason, and your program is no more special than any other program on the system. Instead what you should do is set your app manifest to demand administrative level permission upon launch (which if granted bypasses the file system virtualization, although the user can decline it or possibly not even have the rights to launch something as admin). The other thing you can do is set the ACLs on the folder that your app sits in, and give all users on the machine read/write access to that folder (this would have to be done at install time).

Or you can do things the proper way and store your data files in the %APPDATA% folder, which you have full rights to, although these folders are specific to each individual user of the system.

Upvotes: 1

Roger Lipscombe
Roger Lipscombe

Reputation: 91845

Data shared among all users should go in C:\ProgramData (use Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) to find out where it actually lives -- it can be different between Windows versions).

Data specific to the user should be in SpecialFolder.ApplicationData. If the user has a roaming profile, this is shared between machines.

Data specific to the user that's also specific to the machine should be in SpecialFolder.LocalApplicationData.

If you really need to put something in your program's installation directory, you need to do this with Administrator privileges.

You should either do this by prompting for elevation the first time that the program is run. Preferably, you should do this during installation (because you're already elevated).

Upvotes: 1

Franci Penov
Franci Penov

Reputation: 76001

You should still install your application in Program Files folder. there are good reasons to have it there - a single copy for all users, in a well known locked place where nobody but an admin can tamper with your binaries.

However, any file operation you are doing should be in one of the standard Windows locations for user-writable files. There are several such folders, depending on the file usage model. You can read more about these in the following SO questions :

My winform app uses xml files to store data, where should I store them so Vista users can write to them?
Vista and ProgramData

Upvotes: 1

Pavel Minaev
Pavel Minaev

Reputation: 101585

If your application writes to any files under its install folder (i.e. under Program Files if default path is used), then it is badly written. You shouldn't try to circumvent OS security mechanisms to protect the user from badly written apps; you should rather fix your app so that it works correctly.

And it is, of course, not a .NET issue at all. Any application doing the same thing, no matter which language/framework it's written in, will have the same problem.

Upvotes: 3

Related Questions