473,788 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Track Domain User Logons and Logoffs

My boss asked me to build a program to create a report
with logon/logoff events for all users within our windows
domain. I'm using .Net to do so and decided to have a
program running on the Domain Controler to listen to all
new events and send them to a database. This last part I
haven't worked on yet, cause I can't tell which events are
relevant to write to the db and which are not.

I have managed to listen to all the security log events on
the DC with the following code:

ManagementEvent Watcher1.Query = New
System.Manageme nt.EventQuery(" SELECT * FROM
__InstanceCreat ionEvent WITHIN 60 WHERE TargetInstance
ISA ""Win32_N" & _
"TLogEvent" " and TargetInstance. Logfile
= ""Security" "")
ManagementEvent Watcher1.Scope = New
System.Manageme nt.ManagementSc ope("\\sededc01 \root\CIMV2")

Dim handler As New MyHandler

AddHandler ManagementEvent Watcher1.EventA rrived,
AddressOf handler.Arrived

' Start watching for events
ManagementEvent Watcher1.Start( )
This next Sub send the information of each event to the
output window of vb.Net:

Public Class MyHandler
Public Sub Arrived(ByVal sender As Object, ByVal e
As EventArrivedEve ntArgs)
Dim mbo As ManagementBaseO bject

If Not IsDBNull(e.NewE vent.Properties
("TargetInstanc e")) Then
mbo = CType(e.NewEven t.Properties
("TargetInstanc e").Value, ManagementBaseO bject)

If Not IsDBNull(mbo.Pr operties
("Message").Val ue) Then
Console.WriteLi ne(mbo.Properti es
("Message").Val ue)
Console.WriteLi ne(mbo.Properti es
("ComputerName" ).Value)
Console.WriteLi ne(mbo.Properti es
("Category").Va lue)
Console.WriteLi ne(mbo.Properti es
("EventCode").V alue)
Console.WriteLi ne(mbo.Properti es
("User").Val ue)
End If
End If
End Sub
End Class

My problem is how to interpret the events. There's new
events every second, tons of them. And I'm sure we don't
have people login on or off every second. Even if I limit
my query to TargetInstance. EventCode = "538", I still get
lots of events being generated, with very similar messages.

Here are some output examples:

Message: Successful Network Logon:
User Name: CML2817$
Domain: CMLOURES
Logon ID: (0x0,0xED81BD)
Logon Type: 3
Logon Process: Kerberos
Authentication Package: Kerberos
Workstation Name:
Computer: SEDEDC02
Category: 2
EventCode: 540
User: CMLOURES\CML281 7$

CML2817$ is not a user, it's a computer of the domain. If
this was a logon, who is the user?

Message: User Logoff:
User Name: CML298$
Domain: CMLOURES
Logon ID: (0x0,0xED81D4)
Logon Type: 3
Computer: SEDEDC02
Category: 2
EventCode: 538
User: CMLOURES\CML298 $

If this was a logoff, who is the user?

Is there any way to be sure that one specific event really
is a logon (or logoff) to a computer, to what computer and
what user did it?

Bruno
Nov 18 '05 #1
5 2755
"Bruno Mendonça" <an*******@disc ussions.microso ft.com> wrote in message
news:17******** *************** ******@phx.gbl. ..
My boss asked me to build a program to create a report
with logon/logoff events for all users within our windows
domain. I'm using .Net to do so and decided to have a
program running on the Domain Controler to listen to all
new events and send them to a database. This last part I
haven't worked on yet, cause I can't tell which events are
relevant to write to the db and which are not.

I have managed to listen to all the security log events on
the DC with the following code:

ManagementEvent Watcher1.Query = New
System.Manageme nt.EventQuery(" SELECT * FROM
__InstanceCreat ionEvent WITHIN 60 WHERE TargetInstance
ISA ""Win32_N" & _
"TLogEvent" " and TargetInstance. Logfile
= ""Security" "")
ManagementEvent Watcher1.Scope = New
System.Manageme nt.ManagementSc ope("\\sededc01 \root\CIMV2")

Dim handler As New MyHandler

AddHandler ManagementEvent Watcher1.EventA rrived,
AddressOf handler.Arrived

' Start watching for events
ManagementEvent Watcher1.Start( )
This next Sub send the information of each event to the
output window of vb.Net:

Public Class MyHandler
Public Sub Arrived(ByVal sender As Object, ByVal e
As EventArrivedEve ntArgs)
Dim mbo As ManagementBaseO bject

If Not IsDBNull(e.NewE vent.Properties
("TargetInstanc e")) Then
mbo = CType(e.NewEven t.Properties
("TargetInstanc e").Value, ManagementBaseO bject)

If Not IsDBNull(mbo.Pr operties
("Message").Val ue) Then
Console.WriteLi ne(mbo.Properti es
("Message").Val ue)
Console.WriteLi ne(mbo.Properti es
("ComputerName" ).Value)
Console.WriteLi ne(mbo.Properti es
("Category").Va lue)
Console.WriteLi ne(mbo.Properti es
("EventCode").V alue)
Console.WriteLi ne(mbo.Properti es
("User").Val ue)
End If
End If
End Sub
End Class

My problem is how to interpret the events. There's new
events every second, tons of them. And I'm sure we don't
have people login on or off every second. Even if I limit
my query to TargetInstance. EventCode = "538", I still get
lots of events being generated, with very similar messages.

Here are some output examples:

Message: Successful Network Logon:
User Name: CML2817$
Domain: CMLOURES
Logon ID: (0x0,0xED81BD)
Logon Type: 3
Logon Process: Kerberos
Authentication Package: Kerberos
Workstation Name:
Computer: SEDEDC02
Category: 2
EventCode: 540
User: CMLOURES\CML281 7$

CML2817$ is not a user, it's a computer of the domain. If
this was a logon, who is the user?

Message: User Logoff:
User Name: CML298$
Domain: CMLOURES
Logon ID: (0x0,0xED81D4)
Logon Type: 3
Computer: SEDEDC02
Category: 2
EventCode: 538
User: CMLOURES\CML298 $

If this was a logoff, who is the user?

Is there any way to be sure that one specific event really
is a logon (or logoff) to a computer, to what computer and
what user did it?


In Kerberos, computers are actually logging in and out, as though they were
users. That's what those "$" logins are. Kerberos provides two-way
authentication, where the server can be sure who the client is, and the
client can be sure who the server is.

I believe the event log entry would more accurately say "Principal name"
instead of "user name", as there can be other types of principal logging in.
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #2
>In Kerberos, computers are actually logging in and out,
as though they were
users. That's what those "$" logins are. Kerberos provides two-wayauthentication , where the server can be sure who the client is, and theclient can be sure who the server is.

I believe the event log entry would more accurately say "Principal name"instead of "user name", as there can be other types of principal logging in.--
John Saunders
johnwsaundersi ii at hotmail


This are the properties I can access to:

TargetInstance. Category
TargetInstance. EventCode
TargetInstance. EventIdentifier
TargetInstance. EventType
TargetInstance. RecordNumber
TargetInstance. CategoryString
TargetInstance. ComputerName
TargetInstance. Logfile
TargetInstance. Message
TargetInstance. SourceName
TargetInstance. Type
TargetInstance. TimeGenerated
TargetInstance. TimeWritten
TargetInstance. User

None of them has any additional information about the
user, except for the ones I'm already outputing (Message
and User)

There is also the chance of creating a Management Event on
the Server Explorer of vb.Net and have it listen to log
events. Once you create a NT Event Log Query and start it,
it automatically writes the events to the Output window
and it display additional information. So I created one
and started it. Very quickly I logged to Computer
Dosinsads3 under bruno_mendonca, logged of and stoped the
event query. Maybe 20 seconds went by and from the output
genetrated I retrieved the events refering to either
bruno_mendonca or Dosinsads3. There where 26! For a simple
logon and logoff. I can't tell which one refers to the
logon and which to the logoff...

Here are 3 examples:

1 -

Category = 9; CategoryString = "Account Logon\n";
ComputerName = "SEDEDC02"; EventCode = 673;
InsertionString s =
{"bruno_mendonc a", "CMLOURES.P T", "DOSINSADS3 $", "%{S-1-5-
21-195237392-612787311-312552118-
5296}", "0x40810010 ", "0x17", "10.11.1.36 "};
Message = "Service Ticket Granted:\n\n\tU ser
Name:\t\tbruno_ mendonca\n\n\tU ser
Domain:\t\tCMLO URES.PT\n\n\tSe rvice Name:\t\tDOSINS ADS3
$\n\n\tService ID:\t\t%{S-1-5-21-195237392-612787311-
312552118-5296}\n\n\tTick et Options:\t\t0x4 0810010
\n\n\tTicket Encryption Type:\t0x17\n\n \tClient
Address:\t\t10. 11.1.36\n\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User = "NT
AUTHORITY\\SYST EM"; }; };
2 -

Category = 2; CategoryString = "Logon/Logoff\n";
ComputerName = "SEDEDC02"; EventCode = 540;
InsertionString s =
{"bruno_mendonc a", "CMLOURES", "(0x0,0xEEDE5F) ", "3", "Kerb
eros", "Kerberos", ""};
Message = "Successful Network Logon:\n\n\tUse r
Name:\tbruno_me ndonca\n\n\tDom ain:\t\tCMLOURE S\n\n\tLogon
ID:\t\t(0x0,0xE EDE5F)\n\n\tLog on Type:\t3\n\n\tL ogon
Process:\tKerbe ros\n\n\tAuthen tication
Package:\tKerbe ros\n\n\tWorkst ation Name:\t\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User
= "CMLOURES\\brun o_mendonca"; }; };
3 -

Category = 2; CategoryString = "Logon/Logoff\n";
ComputerName = "SEDEDC02"; EventCode = 540;
InsertionString s =
{"bruno_mendonc a", "CMLOURES", "(0x0,0xEEDE8F) ", "3", "Kerb
eros", "Kerberos", ""};
Message = "Successful Network Logon:\n\n\tUse r
Name:\tbruno_me ndonca\n\n\tDom ain:\t\tCMLOURE S\n\n\tLogon
ID:\t\t(0x0,0xE EDE8F)\n\n\tLog on Type:\t3\n\n\tL ogon
Process:\tKerbe ros\n\n\tAuthen tication
Package:\tKerbe ros\n\n\tWorkst ation Name:\t\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User
= "CMLOURES\\brun o_mendonca"; }; };
The last 2 are identical!

If you wish to see them all look at this 14kb .txt file:
http://www.geocities.com/bmmpt/events.txt

Thanks for the given help though.

Bruno
Nov 18 '05 #3
"Bruno Mendonça" <an*******@disc ussions.microso ft.com> wrote in message
news:17******** *************** ******@phx.gbl. ..
In Kerberos, computers are actually logging in and out,

as though they were
users. That's what those "$" logins are. Kerberos

provides two-way
authentication , where the server can be sure who the

client is, and the
client can be sure who the server is.

I believe the event log entry would more accurately

say "Principal name"
instead of "user name", as there can be other types of

principal logging in.
--
John Saunders
johnwsaundersi ii at hotmail


This are the properties I can access to:

TargetInstance. Category
TargetInstance. EventCode
TargetInstance. EventIdentifier
TargetInstance. EventType
TargetInstance. RecordNumber
TargetInstance. CategoryString
TargetInstance. ComputerName
TargetInstance. Logfile
TargetInstance. Message
TargetInstance. SourceName
TargetInstance. Type
TargetInstance. TimeGenerated
TargetInstance. TimeWritten
TargetInstance. User

None of them has any additional information about the
user, except for the ones I'm already outputing (Message
and User)

There is also the chance of creating a Management Event on
the Server Explorer of vb.Net and have it listen to log
events. Once you create a NT Event Log Query and start it,
it automatically writes the events to the Output window
and it display additional information. So I created one
and started it. Very quickly I logged to Computer
Dosinsads3 under bruno_mendonca, logged of and stoped the
event query. Maybe 20 seconds went by and from the output
genetrated I retrieved the events refering to either
bruno_mendonca or Dosinsads3. There where 26! For a simple
logon and logoff. I can't tell which one refers to the
logon and which to the logoff...

Here are 3 examples:

1 -

Category = 9; CategoryString = "Account Logon\n";
ComputerName = "SEDEDC02"; EventCode = 673;
InsertionString s =
{"bruno_mendonc a", "CMLOURES.P T", "DOSINSADS3 $", "%{S-1-5-
21-195237392-612787311-312552118-
5296}", "0x40810010 ", "0x17", "10.11.1.36 "};
Message = "Service Ticket Granted:\n\n\tU ser
Name:\t\tbruno_ mendonca\n\n\tU ser
Domain:\t\tCMLO URES.PT\n\n\tSe rvice Name:\t\tDOSINS ADS3
$\n\n\tService ID:\t\t%{S-1-5-21-195237392-612787311-
312552118-5296}\n\n\tTick et Options:\t\t0x4 0810010
\n\n\tTicket Encryption Type:\t0x17\n\n \tClient
Address:\t\t10. 11.1.36\n\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User = "NT
AUTHORITY\\SYST EM"; }; };
2 -

Category = 2; CategoryString = "Logon/Logoff\n";
ComputerName = "SEDEDC02"; EventCode = 540;
InsertionString s =
{"bruno_mendonc a", "CMLOURES", "(0x0,0xEEDE5F) ", "3", "Kerb
eros", "Kerberos", ""};
Message = "Successful Network Logon:\n\n\tUse r
Name:\tbruno_me ndonca\n\n\tDom ain:\t\tCMLOURE S\n\n\tLogon
ID:\t\t(0x0,0xE EDE5F)\n\n\tLog on Type:\t3\n\n\tL ogon
Process:\tKerbe ros\n\n\tAuthen tication
Package:\tKerbe ros\n\n\tWorkst ation Name:\t\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User
= "CMLOURES\\brun o_mendonca"; }; };
3 -

Category = 2; CategoryString = "Logon/Logoff\n";
ComputerName = "SEDEDC02"; EventCode = 540;
InsertionString s =
{"bruno_mendonc a", "CMLOURES", "(0x0,0xEEDE8F) ", "3", "Kerb
eros", "Kerberos", ""};
Message = "Successful Network Logon:\n\n\tUse r
Name:\tbruno_me ndonca\n\n\tDom ain:\t\tCMLOURE S\n\n\tLogon
ID:\t\t(0x0,0xE EDE8F)\n\n\tLog on Type:\t3\n\n\tL ogon
Process:\tKerbe ros\n\n\tAuthen tication
Package:\tKerbe ros\n\n\tWorkst ation Name:\t\n";
TimeGenerated = "20040603191448 .000000+060"; Type
= "audit success"; User
= "CMLOURES\\brun o_mendonca"; }; };
The last 2 are identical!

If you wish to see them all look at this 14kb .txt file:
http://www.geocities.com/bmmpt/events.txt


If you look carefully at the last two, you'll see that they have different
logon ids.
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #4
>If you look carefully at the last two, you'll see that
they have different
logon ids.
--
John Saunders
johnwsaundersi ii at hotmail


That's true, but that's the only difference, even the time
is the exact same. I'm assuming they're related to the
same event. And in the list of 26 events I mentioned
before, there are more similar events to these two, where
only the id and possibly the time change. If I was to
consider them as logon events I'd be reporting say 6 or 7
logons (for a period of less that 10 seconds) where really
only one occurred.

Bruno.
Nov 18 '05 #5
<an*******@disc ussions.microso ft.com> wrote in message
news:18******** *************** ******@phx.gbl. ..
If you look carefully at the last two, you'll see that

they have different
logon ids.
--
John Saunders
johnwsaundersi ii at hotmail


That's true, but that's the only difference, even the time
is the exact same. I'm assuming they're related to the
same event. And in the list of 26 events I mentioned
before, there are more similar events to these two, where
only the id and possibly the time change. If I was to
consider them as logon events I'd be reporting say 6 or 7
logons (for a period of less that 10 seconds) where really
only one occurred.


If I were you, I'd try to find documentation on those events somewhere. I
wouldn't be so sure that two different login ids really mean only one login.
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4472
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and keep track of every single user that surfs our websites by the use of sessions. The problem is how to keep track of the session ID across domains. - cookies don't work because not acepted by 40 % of or users and cookies don't work across domains
5
2086
by: | last post by:
(subject included - apologies) <jason@catamaranco.com> wrote in message news:... > Is there a simple way to track users leaving our site to vendors whose wares > we have advertised as a banner on our site.....? > > Some of the vendors we deal with may not have sophisticated tracking devices > to allow us to determine if we are contributing to their sales....
2
3092
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing this by aggregating new content from all databases into a single indexed database and then saving a timestamp in the account database (for the current user) that tells me when the user last read items in the aggregated database.
9
1731
by: diverdon99 | last post by:
I have a database that is using an audit table that logs the machine and user to each record change. My problem is that more than 1 user uses the same login, (this will not change!) hence the audit trail is valueless whn trying to identify an individual. I need a login form that will validate a user against a stored table of passwords and then add that username to any audited entries made during that session. Any ideas to solve this are...
2
1581
by: César Santos | last post by:
Is there a way to find out when someone logs into a computer and when they logoff? I want to see when an employyee has been logging in and out for the last past month. Is that possible?
4
10124
by: Keith-Earl | last post by:
I thought for sure Session End would fire when the user closes his browser, but no luck. The only way I can get the event to fire is to run a Session.Abandon, but is that really practicle? When a user is down they will probably close out the browser or navigate somewhere else. I want to keep a total count of users in an Application state variable but I cannot count on the decrement code to run. What can I do to keep up with Total Users...
4
1455
by: NetRacer | last post by:
i'm checking the logged on user at start of my program. if the user is not in my database (e.g. he uses his private notebook instead of the company desktop), i want to show a login screen where he can enter his windows username and password. can i somehow send this to the logon server to check if they are correct or do i have to enter passwords manually to my database (i want to avoid this)?
5
37047
by: mvr | last post by:
Hi all How to get the Windows current logged user name using Classic ASP. If no direct way are there any work arounds. Thanks mvr
6
6679
Ali Rizwan
by: Ali Rizwan | last post by:
Any body knows how to make bootscreens and logons for XP without using any software. And how to apply Help
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.