Click here to Skip to main content
15,903,201 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: I Just Discovered FXCop Pin
Mark Churchill22-Dec-08 18:59
Mark Churchill22-Dec-08 18:59 
GeneralRe: I Just Discovered FXCop Pin
Wendelius23-Dec-08 3:25
mentorWendelius23-Dec-08 3:25 
QuestionSslStream.AuthenticateAsClient, multiple SslProtocols support and stunnel Pin
Ian Warner19-Dec-08 0:23
Ian Warner19-Dec-08 0:23 
QuestionHow to get WindowsIdentity from domain\ username without password? Pin
Doan Quynh18-Dec-08 23:42
Doan Quynh18-Dec-08 23:42 
AnswerRe: How to get WindowsIdentity from domain\ username without password? Pin
Dave Kreskowiak19-Dec-08 4:14
mveDave Kreskowiak19-Dec-08 4:14 
GeneralRe: How to get WindowsIdentity from domain\ username without password? Pin
Doan Quynh19-Dec-08 15:24
Doan Quynh19-Dec-08 15:24 
GeneralRe: How to get WindowsIdentity from domain\ username without password? Pin
Dave Kreskowiak19-Dec-08 15:45
mveDave Kreskowiak19-Dec-08 15:45 
GeneralRe: How to get WindowsIdentity from domain\ username without password? [modified] Pin
Doan Quynh19-Dec-08 16:18
Doan Quynh19-Dec-08 16:18 
In fact I want to get,set all permission (Read, write, ..in FileSystemRights) in Folder's ACL of one user on WinNT.
I solved it but I have to get WindowsIdentity object of user . Here is the code:





public  void SetFolderPermission(string userName, string fullPath, AccessControlType accessControlType,
                                             FileSystemRights fileAccessPermisson)
      {
          var dInfo = new DirectoryInfo(fullPath);

          DirectorySecurity dSecurity = dInfo.GetAccessControl();
          dSecurity.AddAccessRule(new FileSystemAccessRule(userName, fileAccessPermisson,
                                                           InheritanceFlags.ContainerInherit |
                                                           InheritanceFlags.ObjectInherit, PropagationFlags.None,
                                                           accessControlType));
          dInfo.SetAccessControl(dSecurity);
      }

      public  void RemoveAllFolderPermission(string userName, string fullPath, string password, string domain)
      {
          WindowsIdentity _principal = getWindowsIdentity(userName, domain, password);
          if (_principal == null)
          {
              throw new Exception("Invalid domain\\username or password");
              return;
          }

          var dInfo = new DirectoryInfo(fullPath);

          DirectorySecurity dSecurity = dInfo.GetAccessControl();

          AuthorizationRuleCollection acl = dSecurity.GetAccessRules
              (true, true, typeof (SecurityIdentifier));
          int count = acl.Count;
          int i = 0;
          while (i < count)
          {
              var rule =
                  (FileSystemAccessRule) acl[i];

              if (_principal.User.Equals(rule.IdentityReference))
              {
                  dSecurity.RemoveAccessRule(rule);
              }
              i++;
          }

          dInfo.SetAccessControl(dSecurity);
      }

      [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall)]
      public static extern bool LogonUser(string lpszUsername,
                                          string lpszDomain, string lpszPassword, int dwLogonType,
                                          int dwLogonProvider, ref IntPtr phToken);

      private static WindowsIdentity getWindowsIdentity(string userName, string Domain, string Password)
      {
          bool posix = ((int) Environment.OSVersion.Platform == 128);
          WindowsIdentity user = null;
          try
          {
              if (posix)
              {
                  user = new WindowsIdentity(userName);
              }
              else
              {
                  IntPtr token = IntPtr.Zero;
                  LogonUser(userName, Domain, Password, 2, 0, ref token);
                  if (token == IntPtr.Zero)
                  {
                      return null;
                  }
                  user = new WindowsIdentity(token);
              }
          }
          catch (Exception ex)
          {
              return null;
          }

          return user;
      }

Maybe do that with out using WindowsIdentity ???

QuynhTD

modified on Friday, December 19, 2008 11:47 PM

GeneralRe: How to get WindowsIdentity from domain\ username without password? Pin
Dave Kreskowiak20-Dec-08 4:17
mveDave Kreskowiak20-Dec-08 4:17 
GeneralRe: How to get WindowsIdentity from domain\ username without password? Pin
Doan Quynh21-Dec-08 19:49
Doan Quynh21-Dec-08 19:49 
Questionvb,net buttons Pin
chathini18-Dec-08 20:35
chathini18-Dec-08 20:35 
AnswerRe: vb,net buttons Pin
Thulasee Shan19-Dec-08 0:54
Thulasee Shan19-Dec-08 0:54 
QuestionVB6.0 to VB.NET Pin
sntkn18-Dec-08 20:11
sntkn18-Dec-08 20:11 
AnswerRe: VB6.0 to VB.NET Pin
Oshtri Deka18-Dec-08 21:13
professionalOshtri Deka18-Dec-08 21:13 
AnswerRe: VB6.0 to VB.NET Pin
Dragonfly_Lee24-Dec-08 19:01
Dragonfly_Lee24-Dec-08 19:01 
NewsFree Help from Microsoft for Your Windows Client Applications Pin
brucedkyle18-Dec-08 19:03
brucedkyle18-Dec-08 19:03 
QuestionThreadPool not executing queued jobs Pin
Helfdane18-Dec-08 3:14
Helfdane18-Dec-08 3:14 
AnswerRe: ThreadPool not executing queued jobs Pin
led mike18-Dec-08 7:05
led mike18-Dec-08 7:05 
GeneralRe: ThreadPool not executing queued jobs Pin
Helfdane18-Dec-08 21:53
Helfdane18-Dec-08 21:53 
GeneralRe: ThreadPool not executing queued jobs Pin
led mike19-Dec-08 7:15
led mike19-Dec-08 7:15 
GeneralRe: ThreadPool not executing queued jobs Pin
Helfdane21-Dec-08 23:27
Helfdane21-Dec-08 23:27 
AnswerRe: ThreadPool not executing queued jobs Pin
Dave Kreskowiak18-Dec-08 8:21
mveDave Kreskowiak18-Dec-08 8:21 
GeneralRe: ThreadPool not executing queued jobs Pin
led mike18-Dec-08 8:35
led mike18-Dec-08 8:35 
GeneralRe: ThreadPool not executing queued jobs Pin
Dave Kreskowiak18-Dec-08 9:03
mveDave Kreskowiak18-Dec-08 9:03 
GeneralRe: ThreadPool not executing queued jobs Pin
led mike18-Dec-08 9:05
led mike18-Dec-08 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.