如何通过c#更改AD用户的登录时间?

时间:2015-10-19 04:52:28

标签: c# active-directory

我需要通过c#更新AD用户的登录时间。

用户登录时间为:

  
      
  • 周一 - >星期五:早上7点到晚上7点
  •   
  • 周六:早上7点到下午1点
  •   
  • 星期日:不登录
  •   

我在这篇文章中写道: https://anlai.wordpress.com/2010/09/07/active-directory-permitted-logon-times-with-c-net-3-5-using-system-directoryservices-accountmanagement/

以下是我的代码,但时间未设置为真

DirectoryEntry user = ad.GetUser("nguyen.abc");
            //////////////////////////
            var newTest = new List<TestCRUD_AD.LogonTime>();
            var zone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Monday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 17, 30, 0), zone));
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Tuesday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 17, 30, 0), zone));
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Wednesday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 17, 30, 0), zone));
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Thursday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 17, 30, 0), zone));
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Friday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 17, 30, 0), zone));
            newTest.Add(new TestCRUD_AD.LogonTime(DayOfWeek.Saturday, new DateTime(2011, 1, 1, 7, 0, 0), new DateTime(2011, 1, 1, 12, 30, 0), zone));

            var newResult = PermittedLogonTimes.GetByteMask(newTest);
            //var hoursResult = PermittedLogonTimes.GetLogonTimes(newResult);
            user.Properties["logonHours"].Add(newResult);
            user.CommitChanges();

0 个答案:

没有答案