How to find windows service exe path

前端 未结 9 2020
一整个雨季
一整个雨季 2020-12-25 09:46

I have a windows service and I need to create directory to store some info. The directory path must be relative to the windows service exe file. How can get this exe file pa

9条回答
  •  [愿得一人]
    2020-12-25 10:04

    If you want to get access of Program Files folder or any other using programming you should use the below code which is provide rights to specific folder.

     private bool GrantAccess(string fullPath)
            {
                DirectoryInfo dInfo = new DirectoryInfo(fullPath);
                DirectorySecurity dSecurity = dInfo.GetAccessControl();
                dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                dInfo.SetAccessControl(dSecurity);
                return true;
            }
    

提交回复
热议问题