Home > Net >  How to access permission to files after installation?
How to access permission to files after installation?

Time:11-26

Today I finally ended creating my app. To install app I used "setup project" from Visual Studio 2019 (image of project type). App is written in C# .NET 4.7.2 Framework. So I added some folders and files (image of files and folders here). So I gave my friend *.msi file, he istalled that and something happened - path access denied. I was surprised because when I installed, everything worked, but on my friend's PC when app is trying to write something in file, it gives result that it cannot open it (just doesn't have permission). My friend went to properties of those files and he didn't have writing permissions (image here in polish language). In that picture in Polish, zapis mean "writing", so here is my question: how to make setup project in Visual Studio which gives permission to folders/files to modify them?

CodePudding user response:

In general apps don't have permission to write files to the program folders without elevated permissions. Most apps should write data to the users %appdata% folder you can access that path in c# using:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

CodePudding user response:

Every work on files and folders must be in Users\user folders, in Documents\folder or in the registry. You shouldn't give permissions to the user to modify files on the system or Program Files.

CodePudding user response:

Although windows installer is able to set file permissions, you should not write anything in Program Files. And you should not grant write permissions there due to security considerations and best practices. So, you need to inspect your code and change all places where you are trying to write in a Program Files (or in the folder where your application is placed) to write somewhere else. For example, in the %temp% folder, in the Program Data or in specific folder inside a user's Documents folder or even ask user to specify write location explicitly.

  • Related