2014-11-12 12 views
6

Kullanıcıya klasöre erişim izni vermeye çalışıyorum, ancak programı çalıştırmaya çalıştığımda hata diyor: Some or all identity references could not be translated. Sadece iyi bilinen doğrulanmış kullanıcılar oluşturmak,Bazı veya tüm kimlik başvuruları dönüştürülemiyor C#

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.IO; 
using System.Security; 
using System.Security.AccessControl; 
using System.Security.Principal; 
using System.Management; 
using System.Management.Instrumentation; 

namespace FolderLock 
{ 
    public partial class Lock : Form 
    { 
     public Lock() 
     { 
      InitializeComponent(); 

      SetAccess(); 
     } 

     private void Lock_Load(object sender, EventArgs e) 
     { 

     } 

     public void SetAccess() 
     { 
      DirectoryInfo myDirectoryInfo = new DirectoryInfo("C:/Users/Trov/Desktop/Test"); 

      DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl(); 

      string User = System.Environment.UserDomainName + "\\" + "92111092"; 

      myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Read, AccessControlType.Deny)); 

      myDirectoryInfo.SetAccessControl(myDirectorySecurity); 
     } 

    } 
} 
+0

başarısız satırlarından hangisi ederiz: Burada

kodudur? –

+0

bu hat efendim: 'myDirectorySecurity.AddAccessRule (yeni FileSystemAccessRule (Kullanıcı, FileSystemRights.Read, AccessControlType.Deny));' – Kaoru

+0

Hangi işletim sistemi sürümü? –

cevap

7

buldum bir yol yerine izin vermek veya belirli kullanıcılar tarafından klasöre erişimi reddetmek için çalışmakla: Burada

kullanıyorum kodudur klasöre erişim için reddetmek veya izin vermek.
public void SetAccess() 
     { 
      DirectoryInfo myDirectoryInfo = new DirectoryInfo(@"C:/Users/Trov/Desktop/Test"); 

      var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); 

      DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl(); 

      myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.Read, AccessControlType.Deny)); 

      myDirectoryInfo.SetAccessControl(myDirectorySecurity); 

      this.Hide(); 

      this.Close(); 
     } 

size

+0

Bir kullanıcı adı yerine SID kullanmak benim için hatayı düzeltti. – John81

İlgili konular