Login | |
|
 |
Re: Assign env variables from ldap search - 5/2/2005 6:57:49 AM
|
|
 |
|
| |
token
Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
|
Try the following. ===================================================================================== Option Explicit Dim shell, domain, userID, network, email, displayName, conn, cmd, rs, envUser Set shell = CreateObject("WScript.Shell") Set network = CreateObject("WScript.Network") Set envUser = shell.Environment("USER") Set conn = CreateObject("ADODB.Connection") Set cmd = CreateObject("ADODB.Command") conn.provider = "adsdsoobject" conn.open "active directory provider" cmd.activeconnection = conn userID = shell.ExpandEnvironmentStrings("%USERNAME%") cmd.commandtext = "<LDAP://space/dc=continuium,dc=org>;(&(objectclass=user)(samaccountname=" & userID & "));mail,displayname;subtree" Set rs = cmd.Execute If IsNull(email) Then email = "" Else email = rs.fields("mail") End If If IsNull(displayName) Then displayName = "" Else displayName = rs.fields("displayname") End If envUser("email") = email envUser("displayname") = displayName
|
|
| |
|
|
|
 |
Re: Assign env variables from ldap search - 5/3/2005 6:39:46 AM
|
|
 |
|
| |
bradu
Posts: 10
Score: 0
Joined: 4/30/2005
From:
Status: offline
|
Token, many thanks indeed for your help. The script is running fine on Win2K/XP. However, on some machines the script returns an error. The live script is: ------------------------ Option Explicit Dim shell, domain, userID, network, EMAIL, DISPLAYNAME, conn, cmd, rs, envUser Set shell = CreateObject("WScript.Shell") Set network = CreateObject("WScript.Network") Set envUser = shell.Environment("USER") Set conn = CreateObject("ADODB.Connection") Set cmd = CreateObject("ADODB.Command") conn.provider = "adsdsoobject" conn.open "active directory provider" cmd.activeconnection = conn userID = shell.ExpandEnvironmentStrings("%USERNAME%") cmd.commandtext = "<LDAP://myserver/dc=ho,dc=location-co,dc=country,dc=company,dc=com>;(&(objectclass=user)(samaccountname=" & userID & "));mail,displayname;subtree" Set rs = cmd.Execute If IsNull(email) Then EMAIL = "" Else EMAIL = rs.fields("mail") End If If IsNull(displayName) Then DISPLAYNAME = "" Else DISPLAYNAME = rs.fields("displayname") End If envUser("EMAIL") = EMAIL envUser("DISPLAYNAME") = DISPLAYNAME ------------------------------------------ The following error occurs on some computers no matter what user logs on: Line 28 Char 1 Error: Type mismatch Code: 800A000D Source: Microsoft VBscript runtime error The line 28 contains envUser("EMAIL") = EMAIL Could you please advice on this error? Many thanks in advance.
|
|
| |
|
|
|
|
|