Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've built a Windows Application using c#, on Windows 10.Everything was working fine, so I've created a Setup Wizard project and then built it. Once I install the app, I can open it correctly, but when I try to make some action that writes a text file(with logging purposes) it crashes, thrwoing me the following error message:
Access to the path 'C:\Program Files (x86)\MSProgram\MSProgram\ErrorLog.log' is denied.

What I have tried:

No idea. Need your help to get the solution
Posted
Updated 27-May-20 3:47am

Quote:
'C:\Program Files (x86)\MSProgram\MSProgram\ErrorLog.log'
that's not a great path to log to - it's usually protected and rightly so, what if someone over-wrote an OS file in [Program Files (x86)] ??

You 'may' be able to 'require' Admin privs and do it by elevating your prog, but just because you can doesnt mean you should .. the setup Wizard should get a non 'system'/OS path, and use that as a config element, maybe default to Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
 
Share this answer
 
v2
The folders at C:\Program Files (x86) are for use by the system. You should never try to store data there. You should use one of the users data folders such as AppData/Local or AppData/Roaming for any data that needs to be created or read by your application. See Application.LocalUserAppDataPath Property (System.Windows.Forms) | Microsoft Docs[^] for how to get the path.
 
Share this answer
 
You cannot use the Program Files folder for storing mutable files anymore, for security reasons.

You could instead use the ProgramData folder, or the AppData folder of user's profile directory, for files which will be modified by your application. The former is more suitable for application scope data, and the latter for user scope data.
 
Share this answer
 
Comments
Member 13458729 27-May-20 10:04am    
i just want to exclude the debug.log from setup
phil.o 27-May-20 10:27am    
The problem isn't in the setup. It is in your code relying on a file which it is expecting to find in the Program Files folder. Change the code so that this file is placed in one of the directories I told, and you will get rid of the issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900