开发者

Active Directory Programming help needed

开发者 https://www.devze.com 2022-12-22 13:12 出处:网络
I want to make Windows Service in .NET which has to run on Windows Server 2003, 2008. The main funct开发者_C百科ionalities i need are:

I want to make Windows Service in .NET which has to run on Windows Server 2003, 2008. The main funct开发者_C百科ionalities i need are:

As soon as a network user logs in, Display his:

  1. User name in Active Directory
  2. Domain
  3. Ip Address from where he connected

I do not want to install or run any program/script on the client machine.

Any help on how to go about developing this will be greatly appreciated. i saw some articles explaining this using the System.Environment namespace and some others but they only shed light for the local logged on user.


One workaround is to monitor the security event log on the windows server machine.

This assumes that the windows server 2003/2008 domain controller is set up to log successful ‘Audit logon events’.

     using System.Diagnostics;
     ...
     myLog = new EventLog("Security");
     myLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
     ...

    /// <summary>
    /// A new event is logged in the security event log.
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    private void OnEntryWritten(object source, EntryWrittenEventArgs e)
    {
        LogNewEntry(e.Entry);
    }

Windows server 2003

You can identify a logon with event ID's 528 and 540.

The EventLogEntry instance contains property UserName which contains Domain\UserName.

The EventLogEntry instance also contains property ReplacementStrings.

To find the ip address you have to look at the ReplacementStrings string array property [13].

Windows server 2008

You can identify a logon with event ID 4624.

To find the UserName you have to look at the ReplacementStrings string array property [5].

To find the Domain you have to look at the ReplacementStrings string array property [6].

To find the ip address you have to look at the ReplacementStrings string array property [18].


Assuming you can use .NET 3.5, have a look at the System.DirectoryServices.ActiveDirectory namespace. The classes in there should provide a good starting point for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消