PDA

View Full Version : How to get currently logged on user's account name?



agarwaldvk
04-27-2010, 05:52 PM
Hi Everybody

I am trying to get the details of the currently logged on user as a part of the process for generating a report - the requirement being that the report should contain the name (and not the userid - which I can get from the API function "apiGetUserName()" of the user that generated that report so that he/she can be contacted should anyone have any clarifications on that report.

For example, the above mentioned API function will give me the userid like "A256322" but it wouldn't tell me the name of that user. I need the name as in "John Smith".

I am told that there is an API function that I can use to get that detail and that is called "LookupAccountName()" API function but that needs a hell of a lot of parameters loke so :-

LookupAccountNameA(lpSystemName As String, ByVal lpAccountName As String, sid As Any, cbSid As Long, ByVal ReferencedDomainName As String, cbReferencedDomainName As Long, peUse As Long) As Long

Can this function get the values for these arguments by itself or is there an easier way to do so, that is, are there API functions that can be used as feeds for the various arguments to this function?


Best regards



Deepak Agarwal

agarwaldvk
04-28-2010, 08:01 PM
Guys

Don't worry about this anymore!

I have found out how to do it now!



Best regards



Deepak Agarwal

jolivanes
04-28-2010, 08:19 PM
Would be nice to know what the answer is for other people.

Aussiebear
04-28-2010, 11:39 PM
Would be nice to know what the answer is for other people.

I'm surprised at the number of people lately who take the time to post a thread on a public forum, and then on finding a solution to the issue, seem to think that there's no benefit in also posting the solution.

Sharing of information is highly regarded in these forums, in fact we encourage all participants to do so. Everyone then has the opportunity to learn.

jolivanes
04-28-2010, 11:57 PM
To me it should be common courtesy but I might be of the old school.
I am sure agarwaldvk will mend his oversight.

Regards
John

agarwaldvk
04-30-2010, 03:14 AM
Hey Guys

My most sinceres apologies first.

Now to why I did not post the solution that I found. I lay no claims to be the "Know it All" person at all.

First, nobody responded to it for sometime - I took that to be the case that this is a subject matter which no one has had a need to do this sort of thing in their past works and that was why nobody would have responded to it. The reason for this assumption was that I have been doing VBA coding for a reasonble amount of time (even though I do not work in the core IT sector) and I thought that if I have never had a need for such a thing, its obvious that it is not something that comes often enough. It was reinforced by the fact that there were more than 15 views but no responses. And secondly, I did not come up with the solution by my own code - it was something that I found on a couple of web sites and combined the contents of those and tested the combined code with minor modifications and fortunately it worked.

I have a lot of help from this forum in the past - and if this helps anyone at all, it would be my pleasure in its entirety. I am at home at the moment and I do not have the code here with me. But I make this promise that I will post it on Monday from work.

Sorry to hav offended you guys but trust me it was never intended.


Best regards



Deepak Agarwal