Access denied to directory

Asked

Viewed 93 times

-1

Hello,

I have a small project that is working perfectly. After finishing programming I generated an installer using the Microsoft Visual Studio Installer Project.

The project installs correctly but when I try to use, it denied access to the directory.

It is installed inside the "Program File" folder and the program handles files inside this folder.

So how do I give administrator access inside the folder to the application executable.

Normally access the files like this:

var pathArqFinal = Environment.CurrentDirector + "\Filename.txt";

Thank you very much.

Raimundo

  • Check if the problem occurs when you open the application as an administrator.

  • If opening as administrator does not occur, runs perfectly. As I make it permanent, without having to run every time as administrator?

  • You have to run as an administrator if the folder is progamma files.

1 answer

2


If it were possible to edit what is inside program files without permission it would be a huge security breach, which I recommend at least is you use the user level folder, but for each user will be generated a . txt (depends on what you have already done and need):

var pathArqFinal = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Filename.txt";

According to microsoft website: https://docs.microsoft.com/pt-br/dotnet/api/system.environment.specialfolder?view=netframework-4.8

The directory that serves as a common repository for app-specific data for the current mobile user. A mobile user works on more than one computer on a network. A mobile user’s profile is maintained on a server on the network and is loaded into a system when the user logs on.

If it is for all users could use the CommonApplicationData, thus:

var pathArqFinal = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\Filename.txt";

The directory that serves as a common repository for application-specific data that is used by all users.

This way it will be a file used by all, the problem is that you will need to be careful with "race condition", because multiple instances of the application may get tangled when recording.

  • Windows also has a generic "all users" directory, doesn’t it? Or "public".

  • I thought I could give Adm permission just inside the folder of my application. Anyway thank you, it worked perfectly.

  • 1

    @bfavaretto the text of the doc en was wrong and made me think it was for something else, even if the name was similar to that of the first enumerator quoted in the answer, see how this: O diretório que serve como um repositório comum para dados específicos do aplicativo que são usados por "todos os aplicativos"., is all apps, so I cessed to make sure https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.8#System_environment_specialfolder_commonapplicationdata, the right one was "by all users". I adjusted the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.