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

bmarrottAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.