Jump to content
Sign in to follow this  
redfive19

Query AD for login script name & profile path

Recommended Posts

redfive19

Hi guys,

Having an issue finding the right LDAP commands to query AD to find out the current logged on user's login script name and profile path. Has anyone tried this before? thanks!

EDIT

NVM figured it out....

Dim $objConnection, $objCommand, $objRootLDAP, $strDNSDomain, $strUserorMachine, $oMyError, $cn, $objGroup, $profilepath, $logonscript
Const $ADS_SCOPE_ONELEVEL = 1
Const $ADS_SCOPE_SUBTREE = 2
Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000

$userDN = _GetUserDN(@UserName) ;gets the DN of the logged on user

$userinfoRETURN1 = _GetUserInfo(@UserName, $userDN) ;gets user info from AD

MsgBox(0, '', $profilepath)
MsgBox(0, '', $logonscript)

Func _GetUserDN($usercn)
    $objNetwork = ObjCreate("Wscript.Network" )
    $objShell = ObjCreate("Shell.Application")
    $objSysInfo = ObjCreate("ADSystemInfo")
    $strComputerDN = $objSysInfo.computerName
    $strUserDN = $objSysInfo.userName
    $objComputer = ObjGet("LDAP://" & $strComputerDN)
    $objUser = ObjGet("LDAP://" & $strUserDN)
    MsgBox(0, '', $strUserDN)
    Return $strUserDN
EndFunc   ;==>_GetDN

Func _GetUserInfo($user, $user_dn)
    Const $ADS_NAME_INITTYPE_GC = 3
    Const $ADS_NAME_TYPE_NT4 = 3
    Const $ADS_NAME_TYPE_1779 = 1
    $oMyError = ObjEvent("AutoIt.Error", "ComError")
    $objRootDSE = ObjGet("LDAP://RootDSE")
    ;~ $user_dn = _GetUserDN($user)
;~  MsgBox(0, '$userdn', $user_dn)
    $UserObj = ObjGet("LDAP://" & $user_dn)
    If IsObj($UserObj) Then
        $profilepath = $UserObj.profilePath
        $logonscript = $UserObj.scriptPath
        $FirstName3 = $UserObj.FirstName
        $LastName3 = $UserObj.LastName
        $FullName3 = $UserObj.FullName
        $Dept3 = $UserObj.Department
        $Office3 = $UserObj.physicalDeliveryOfficeName
        $Phone3 = $UserObj.TelephoneNumber
        $Email3 = $UserObj.EmailAddress
        $Description3 = $UserObj.Description
        $Title3 = $UserObj.Title
    Else

    EndIf

EndFunc
Edited by redfive19

Share this post


Link to post
Share on other sites
lgwapnitsky

Hi guys,

Having an issue finding the right LDAP commands to query AD to find out the current logged on user's login script name and profile path. Has anyone tried this before? thanks!

EDIT

NVM figured it out....

Dim $objConnection, $objCommand, $objRootLDAP, $strDNSDomain, $strUserorMachine, $oMyError, $cn, $objGroup, $profilepath, $logonscript
Const $ADS_SCOPE_ONELEVEL = 1
Const $ADS_SCOPE_SUBTREE = 2
Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000

$userDN = _GetUserDN(@UserName) ;gets the DN of the logged on user

$userinfoRETURN1 = _GetUserInfo(@UserName, $userDN) ;gets user info from AD

MsgBox(0, '', $profilepath)
MsgBox(0, '', $logonscript)

Func _GetUserDN($usercn)
    $objNetwork = ObjCreate("Wscript.Network" )
    $objShell = ObjCreate("Shell.Application")
    $objSysInfo = ObjCreate("ADSystemInfo")
    $strComputerDN = $objSysInfo.computerName
    $strUserDN = $objSysInfo.userName
    $objComputer = ObjGet("LDAP://" & $strComputerDN)
    $objUser = ObjGet("LDAP://" & $strUserDN)
    MsgBox(0, '', $strUserDN)
    Return $strUserDN
EndFunc ;==>_GetDN

Func _GetUserInfo($user, $user_dn)
    Const $ADS_NAME_INITTYPE_GC = 3
    Const $ADS_NAME_TYPE_NT4 = 3
    Const $ADS_NAME_TYPE_1779 = 1
    $oMyError = ObjEvent("AutoIt.Error", "ComError")
    $objRootDSE = ObjGet("LDAP://RootDSE")
    ;~ $user_dn = _GetUserDN($user)
;~  MsgBox(0, '$userdn', $user_dn)
    $UserObj = ObjGet("LDAP://" & $user_dn)
    If IsObj($UserObj) Then
        $profilepath = $UserObj.profilePath
        $logonscript = $UserObj.scriptPath
        $FirstName3 = $UserObj.FirstName
        $LastName3 = $UserObj.LastName
        $FullName3 = $UserObj.FullName
        $Dept3 = $UserObj.Department
        $Office3 = $UserObj.physicalDeliveryOfficeName
        $Phone3 = $UserObj.TelephoneNumber
        $Email3 = $UserObj.EmailAddress
        $Description3 = $UserObj.Description
        $Title3 = $UserObj.Title
    Else

    EndIf

EndFunc

Have you tried using the Active Directory UDF and the _AD_GetObjectAttribute function?

The code from here should help you out as well

Edited by lgwapnitsky

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.