Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6690081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:35:41+00:00 2026-05-26T05:35:41+00:00

I search for a long time how I can define permitted logon hours on

  • 0

I search for a long time how I can define permitted logon hours on group like it is possible to do with user from the account tab in Active Directory.

I already have a class in c# that can make queries to returns a list of all permitted hours of a user with the help ‘logonhours’ properties.

  public byte[] GetLogonHours(string userName, string password, string path)
  {
     DirectoryEntry entry = this.GetUserAccount(userName, path);

     return (byte[])entry.Properties["logonHours"].Value;
  }

  public DirectoryEntry GetUserAccount(string username, string path)
  {
     using (DirectoryEntry objRootEntry = new DirectoryEntry(path))
     {
        using (DirectorySearcher objAdSearcher = new DirectorySearcher(objRootEntry))
        {
           objAdSearcher.Filter = "(&(objectClass=user)(samAccountName=" + username + "))";

           SearchResult objResult = objAdSearcher.FindOne();

           if (objResult != null)
           {
              return objResult.GetDirectoryEntry();
           }
        }
     }

     return null;
  }

I used this post to help me understanding how I can query the logon hours:

http://anlai.wordpress.com/2010/09/07/active-directory-permitted-logon-times-with-c-net-3-5-using-system-directoryservices-accountmanagement/

It is important to understand that I don’t want a feature to know when the last time a user has been logged. What I have is a feature that prevent a user logging at some moments.

What I want is a feature that can apply logon hours for a group of users and I can query the Active Directory with c# to get these logon hours information.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:35:42+00:00Added an answer on May 26, 2026 at 5:35 am

    In my understanding logon hours information is a user information. As discribed in HOW TO: Limit User Logon Time in a Domain in Windows Server 2003 pointed by @Knite you can change it :

    1. User by user, whatever if you loop on a list of user
    2. Applying a GPO to an organizationalUnit users belongs to

    In your case you can loop for all the members of a group and change their logon hours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

been trying to search the reason for this error for a long time and
I have search for a long time to get this thing work. What I
I'm performing array calculations that are taking a long time to complete. I'd like
After doing a long search on stackoverflow i didn't find any one talked about
How long after a document is fed to the Google Search Appliance using a
i have a long string variable and i want to search in it for
I need to do a search and replace on long text strings. I want
Executive summary: How can I define an arbitrarily-sized 2D array in C? How can
I have now used way too long time, trying to figure out a problem,
I've been hunting for a long time for this, but despite my intuition that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.