[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5687
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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