Grant write permission during installation

我是研究僧i 提交于 2019-12-25 02:22:39

问题


I have a application in which i am implementing log4net.dll . i installed this application on different computers and its working fine.

my application installs at C:\ProgramFile\myApplication.

However the problem is when the user does not have write permission on under ProgramFile. It does not write a log ?

I am wondering is there any way that i could assign all access permission the folder during installation. I went through different articles but could not find any satisfactory answer.

Any help would be appreciated.


回答1:


You should not put your log files in the (sub)folder of your application! Put them where it is certain that every user has write permissions, e.g. $Appdata or $LocalAppdata (which I prefer for log files)

Example for log4net config:

<file value="${APPDATA}/My Company/My Product/Logs/My Application.log" />

taken from here:

http://malor.se/blog/?p=23




回答2:


I worked on a similar problem within a WIX installer, here is the code :

DirectoryInfo directoryInfo = new DirectoryInfo(session["..."]);

DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();
SecurityIdentifier localService = new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null);
FileSystemAccessRule directoryAccessRule = new FileSystemAccessRule(localService, FileSystemRights.FullControl, AccessControlType.Allow);
directorySecurity.AddAccessRule(directoryAccessRule);
directoryInfo.SetAccessControl(directorySecurity);

The Local Service account is granted full access to a folder. Just change the SID of the Local Service user by the SID of the user who will use your application.



来源:https://stackoverflow.com/questions/21288641/grant-write-permission-during-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!