Mike wrote:
>I am trying to create a script that will pull the logon user name then
>perform a LDAP query to find users homedrive and other attribut
>information. For example:
>
> Set objNet = CreateObject("WScript.NetWork")
> struser = ucase(objNet.username)
>
> Set objUser = GetObject("LDAP://CN=" & struser &
> ",OU=Users,DC=test,DC=com")
> strhdir = objUser.HomeDirectory
> msgbox(strhdir)
>
> But this does not work because the logon username is "JDDoe", but in order
> to get this to work I have to use "Doe\, John" in the cn to get this to
> work.
>
> Is there any way to automaticall convert the logon username to the cn
> name.
Retrieve the Distinguished Name of the current user from the ADSystemInfo
object. For example:
===========
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
strHomeDir = objUser.homeDirectory
===========
The name retrieved from the wshNetwork object is the NT name (pre-Windows
2000 logon name) of the current user, is not necessarily the same as the
Common Name (the value of the cn attribute) of the user. If any characters
of the user Distinguished Name needs to be escaped (like the comma), the
value retrieved from ADSystemInfo will be escaped. The one exception is the
forward slash "/", but hopefully none of your names use that character. If
they do, you will need replace instances of "/" with "\/".
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--