简体   繁体   中英

Grant write permission during installation

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.

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, eg $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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM