We help IT Professionals succeed at work.

obtain domain username in vbs

resourcepc
resourcepc asked
on
699 Views
Last Modified: 2009-07-07
I need the code to obtain the username for a vbs logon script.
Comment
Watch Question

Author

Commented:
and also the code to find out what groups the person belongs to so I can perfom IF THEN statements to map drives.

Thanks,

Dave
To obtain the domain\username use the following:

Me.User.Identity.Name.ToString

There is an is IsInRole(String) method that determines whether the current user belongs to a specified Windows user group. See this msdn listing:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsPrincipalClassIsInRoleTopic2.asp

There are two versions of this that you may be interested in. At the above address, it will tell you how to check if a user is in a Windows Group, however there is also info regarding the Windows Builtin Roles:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsPrincipalClassIsInRoleTopic3.asp

This will do the trick for you if you are checking against a known list of Windows Groups. If you are looking to list the groups for which a user is a member, I have to do a little digging for you.

Hope this helps and let me know if you need more assistance.

Cheers.
I am sorry. The above is for VB.NET. I was too quick to answer.

VBS Examples:

How to Enumerate Users in a Group with VBScript
http://computerperformance.co.uk/vbscript/vbscript_group_enumerate_members.htm

How to Enumerate Groups that a User is a memberOf
http://computerperformance.co.uk/vbscript/vbscript_group_user_memberof.htm

This site could also be helpful: http://www.rlmueller.net/Logon2.htm - See the link to the .txt file...


Using VBScript, how can I obtain the username of the currently logged-on user? (There are two Listings, Listing 1 and Listing 2 that show quick examples)
http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/21569/21569.html

Sorry for the initial confusion.

Hope this helps.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Thank you for the grade!

Regards,
Lynn

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.