[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get User ID from EVENTLOGRECORD

Posted on 1997-07-09
9
Medium Priority
?
617 Views
Last Modified: 2013-12-03
I think this question is quite straight forward.....but I dun know how to go about it.....my question:

How can I get User ID from EVENTLOGRECORD?  

Example:
If I have a EVENTLOGRECORD pointer that points to a record, how do I print that user ID using that record pointer, to a string?

I think that maybe using UserSidOffset or/and UserSidLength might help.....but I don't know how to.

Any suggestion will be appreciated.
0
Comment
Question by:YamSeng
  • 6
  • 3
9 Comments
 
LVL 1

Author Comment

by:YamSeng
ID: 1400483
Adjusted points to 20
0
 
LVL 5

Accepted Solution

by:
y96andha earned 200 total points
ID: 1400484
You need to use the LookupAccountSid function. Just pass in the pointer to the SID, and you will receive the name of the user and the domain the account was found on.
0
 
LVL 1

Author Comment

by:YamSeng
ID: 1400485
Ho do I get the sid?

pEventLogRecord + pEventLogRecord->UserSidOffset  ?
and pEventLogRecord->UserSidLength ?

Can show me a sample?  
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Expert Comment

by:y96andha
ID: 1400486
20 points is not much.

if(pEventLogRecord->UserSidLength) {
 PSID sp;
 sp = (PSID)(((char *)pEventLogRecord) + pEventLogRecord->UserSidOffset);

 SID_NAME_USE snu;
 DWORD len1,len2;
 int ok;
 TCHAR name[256],dom[256];
 len1=len2=256;
 ok = LookupAccountSid(0,sp,name,&len1,dom,&len2,&snu);
 if(ok) {
   // Success
 } else {
  printf("Error: %d\n",GetLastError());  
 }
}

I have not tested this code, but it should work.
0
 
LVL 1

Author Comment

by:YamSeng
ID: 1400487
sorry about the points, but I a new member and I dun have much points.....

anyway, I've increased the points....
0
 
LVL 1

Author Comment

by:YamSeng
ID: 1400488
If you can help me, I can only offer this much....sorry!
0
 
LVL 1

Author Comment

by:YamSeng
ID: 1400489
I've tried the codes, but found that it gives the user that I do not want.  I want the user name.

If you go to event viewer, you can see that under security log, details for eventID 529 (failed to logon) has 2 "user".  One is "user" the other is "user name"

For example:
If my name is ash and I failed to logon to NT workstation, the event viewer should show

user = system
username = ash

The user name is the value I want to find out.....

thanks!

0
 
LVL 5

Expert Comment

by:y96andha
ID: 1400490
OK, you mean the name in the description box?

This is found in one of the strings, I am not sure which one, and I currently don't have any such entries in my log. You could test it out yourself. The strings are accessed like this:

 TCHAR *p;
 p = (TCHAR *)(((char *)pEventLogRecord) + pEventLogRecord->StringOffset);

 int i;
 for(i=0;i<pEventLogRecord->NumStrings;i++) {
  wprintf(L"String %d : %s\n", i, p);
  p+=_tcslen(p)+1;
 }

0
 
LVL 1

Author Comment

by:YamSeng
ID: 1400491
Thanks!!!  I've got it...

FYI, the user name is in string 0.  
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question