Fix permissions
This commit is contained in:
parent
0d4c30d64f
commit
46a86f53ae
|
@ -42,17 +42,22 @@ namespace DontTouchMyFlash
|
||||||
{
|
{
|
||||||
FileSecurity fileS = File.GetAccessControl(filepath);
|
FileSecurity fileS = File.GetAccessControl(filepath);
|
||||||
|
|
||||||
IdentityReference sid = fileS.GetOwner(typeof(SecurityIdentifier));
|
SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
|
||||||
string ntAccount = sid.Translate(typeof(NTAccount)).ToString();
|
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
|
||||||
if(ntAccount == @"NT SERVICE\TrustedInstaller")
|
|
||||||
{
|
|
||||||
SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
|
|
||||||
fileS.SetOwner(cu);
|
|
||||||
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Allow));
|
|
||||||
|
|
||||||
File.SetAccessControl(filepath, fileS);
|
fileS.SetOwner(cu);
|
||||||
}
|
fileS.SetAccessRuleProtection(false, false);
|
||||||
|
|
||||||
|
fileS.RemoveAccessRuleAll(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Deny));
|
||||||
|
fileS.RemoveAccessRuleAll(new FileSystemAccessRule(cu, FileSystemRights.FullControl, AccessControlType.Deny));
|
||||||
|
|
||||||
|
fileS.SetAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, AccessControlType.Allow));
|
||||||
|
fileS.SetAccessRule(new FileSystemAccessRule(cu, FileSystemRights.FullControl , AccessControlType.Allow));
|
||||||
|
|
||||||
|
File.SetAccessControl(filepath, fileS);
|
||||||
|
File.SetAttributes(filepath, FileAttributes.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckFileAndAdd(string filepath)
|
public bool CheckFileAndAdd(string filepath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
Loading…
Reference in New Issue