views:

57

answers:

3

In my project I have to create some files and directories into my app folder which is into program files. But in vista it is giving me error that I dont have access to create file. What should I do now for giving access ? Also it not let me access the registry !!

A: 

Can you turn the UAC off? Or Login as administrator? The chances are that you are creating the folder in the wrong place.

Ngu Soon Hui
My customer is very much angry with me because other software doing it perfectly But not mine.
Barun
No it is only program file and my install folder.
Barun
Turning UAC off is never a solution. Expecting your customers to do it is even worse.
Zooba
+1  A: 

Vista and Win 7 have the Program Files folder locked down so you can't write to it with a basic user account. If you need to create folders there, then you should do it in the installer. Otherwise you can use the user's Application Data folder in their profile.

The only other way is to modify the permissions on the installation folder at install time.

Andrew Cooper
But other softwares doing it why I cant ?
Barun
Is this restiction only for folder ? Can I create files into my app folder after installation ?
Barun
+1, but I'd avoid modifying the folder permissions and either include all the files in the installer or store them elsewhere.
Zooba
@Zooba - Agreed. Modifying permissions is not the preferred option.
Andrew Cooper
@Barun - Have a look at the permissions on the installation folders for the other software. The restriction is based on NTFS permissions and prevents basic users from creating files or folders of any kind under your installation folder after installation. For a long time the AppData section of the user profile has been the correct place to store configuration data - Vista and Win 7 are just enforcing that.
Andrew Cooper
Thanks fro reply . My problem is solved.
Barun
+4  A: 

The program folder is not the place to store application data. There is an %APPDATA% folder for that - you are supposed to store your data there.

Use System.Environment.SpecialFolder and System.Environment.GetFolderPath to obtain the path leading to the correct directory.

Also, you need to differentiate between just creating a folder and putting some files in there (for example during installation) or writing to the program folder at runtime, while typically running under a limited account.

The reason for this difference is simply that installation routines and setups run with elevated privileges under Vista / Windows 7, thus those are allowed to create folders and files there. Still, those files are not supposed to be written to at runtime of your application.

So, what is it you want to do? Write data at runtime, or put some files (i.e. dependencies) in your application folder at a single time? If it's the first, comply with the rules and use the %APPDATA% folder. If it's the second, create an installer / setup routine.

Jim Brissom
and what about registry access ? It also preventing me write anything to registry ...
Barun
Same - you are probably writing to the wrong place in the registry. Please read an article about the new UAC, virtualization and the security model in Vista an upwards. You cannot simply implement software like you used to, ignoring the changes. Here is a start: http://msdn.microsoft.com/en-us/library/bb756960.aspx
Jim Brissom
You need to write to the HKEY_Current_User hive
Andrew Cooper