• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5708
  • Last Modified:

LDAP - Get user login script from AD

I need a simple VB scripted that will query and active directory domain controller for the login script path from thier users profile information.

I am using the following to get the username from the local computer....

Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
strUsername = ObjEnv("Username")

I need to know how to do an LDAP query using the username to retrieve the login script information.

Any help would be greatly appreciated

0
bmarrott
Asked:
bmarrott
  • 5
  • 3
2 Solutions
 
RobSampsonCommented:
Hi, if you are running a script locally, you can use the code below to return the path to the current user's logon script.

If you're after an example of how to clear that value for all users in your AD, you can look here:

How Can I Clear the Logon Script Path for All My Users?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0908.mspx

Regards,

Rob.
Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName
MsgBox objUser.ScriptPath

Open in new window

0
 
RobSampsonCommented:
Oh, forgot a closing bracket...
Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.ScriptPath

Open in new window

0
 
bmarrottAuthor Commented:
That works great, and simple. Since you obvoiusly know more that I do, let me ask you the next part. I want this script to be versitile as possible. Is there a way to use DNS to find a domain controller? If it cant find a domain controller to return a message saying the domain isnt available. If a DNS entry is returned to test to make sure its active? Thoughts?
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
RobSampsonCommented:
I'm not so sure I follow.....you *can* obtain a list of all domain controllers by connecting to the Active Directory, but it sounds like you want to check a DC first....

In that case, you could ping the server listed in the DOS variable "%LOGONSERVER%", and you'd know which server was authenticated to....

Is that sort of what you're after?

Regards,

Rob.
0
 
bmarrottAuthor Commented:
Don' t worry about it, you took can of what I needed.

Thansk!!!!!!
0
 
bmarrottAuthor Commented:
Just to post my final script for others.....

This script will get the login script path information for a Active Directory user and execute it.

dim strScriptPath
Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
strScriptPath = objUser.ScriptPath

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%LOGONSERVER%\NETLOGON\" & strScriptPath
strScriptPath = ""
0
 
RobSampsonCommented:
OK thanks.  That's great.  Glad to help.

Please don't forget that you can close the question if your requirements have been met.

Regards,

Rob.
0
 
RobSampsonCommented:
Oh, you did request the closure....ignore me, we'll just wait out the four days....  :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now