Jump to content

Active Directory - Get CommonName from UserName


Recommended Posts

I can get the UserName (aSAMAccountName or otherwise) on a Windows 7 PC pretty easily (from the environment variables), but I need to get the CommonName so I can do some active directory queires - anyone know how to do this?

I've attached an example that gets the active directory groups of a user - problem is, I can't get the CommonName to input into it (eg: on my domain, my UserName is "christopher_relf" which doesn't work, my CommonName is "christopher relf" which works fine).

Get User\'s Groups.vi

Link to comment

I've attached an example that gets the active directory groups of a user - problem is, I can't get the CommonName to input into it (eg: on my domain, my UserName is "christopher_relf" which doesn't work, my CommonName is "christopher relf" which works fine).

I apologize in advance, but have to ask the obvious question: do the CommonName and UserName always follow a format where you can derive one from the other, or was that just the case in your example?

Link to comment

This command line seems to work: net group /domain <groupname>*

I tested it on my XP machine and got the full list of names, don't know if it works the same with Win7. Assuming ActiveDirectory didn't change syntax... it should.

Credits

EDIT:

Reading your question again, I guess it doesn't answer your question which is how to get CommonName from UserName... If you don't know the group, how can you get a list. :frusty:

Link to comment

It's pretty easy to get through WMI:

Set objSysInfo = CreateObject("ADSystemInfo") strUserDN = objSysInfo.UserNameSet objUser = GetObject("LDAP://" &amp; strUserDN)Wscript.Echo objUser.cn

but I don't know a slick way of getting that information back to LabVIEW outside of writing it to temp file.

ref: http://www.windowsitpro.com/article/tips/q-how-can-my-batch-retrieve-the-common-name-of-the-current-user-.aspx

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.