Link to home
Start Free TrialLog in
Avatar of GrahamAtJobserve
GrahamAtJobserve

asked on

Get current User, using ADSI

A simple question this one. All I need to do is to get the current NT user, using Active Directory Service.

Avatar of RainUK
RainUK

Do you wish to get the name of the user on the machine the app is running on or on another computer across the network?

Well below is simple code to get the local computer users name (Of course you could just use the Win32 API GetUserName)

Dim sys As New ADSystemInfo
Debug.print "User: " & sys.UserName
Debug.print "Computer: " & sys.ComputerName
Debug.print "Domain: " & sys.DomainDNSName
Debug.print "PDC Role Owner: " & sys.PDCRoleOwner
Avatar of GrahamAtJobserve

ASKER

I wish to get the name of the current user, on the machine the app is running on.

NOT using the API. I've got this function already, but trying to 'upgrade' to ADSI. The upgrade is seeming like a retrograde step at present. Its slower than before.

Tried the code - won't compile. What references does it need to run?
I have the references, I think. I'm getting the intellisense functions appear, and its in the object browser, but getting the '429 - activex component cant create object' messgae
Have you selected the reference: Active DS Type Library?
Should be in C:\WinNT\System32\activeds.tlb

When you run the app is it on a dev machine? or a prod machine. Because if you don;t install the activeds.tlb on the client, then you will get the ActiveX 429 error

Yes, its selected, and working on my own PC in dev. I'm getting other ADSI functions to work, eg lists of groups, users etc,  I just can't get who the current user is.


Are you running version 2.5 of ADSI?
Also what is your dev machine and the client OS?

If client is NT4 try this:

Dim ntsys As New WinNTSystemInfo
Debug.print "User: " & ntsys.UserName
Debug.print "Computer: " & ntsys.ComputerName
Debug.print "Domain: " & ntsys.DomainName
Debug.print "PDC: " & ntsys.PDC


But ActiveX 429 is usually the fact that you do not have the correct COM object int his case the Activeds.tlb on the computer.
ASKER CERTIFIED SOLUTION
Avatar of RainUK
RainUK

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thats perfect, exactly what I needed.

Thaknk you.