PDA

View Full Version : New to VBscript Coding, Need Guidance


wolfess
04-21-2005, 02:12 PM
Hi,

I need to re-write our organization's logon in script which is written totally in command line to a more intelligent login script using VBcript. I'm new to programming in VBscript, but not new to programming.

Anyway, I need to iterate the security group membership list for a user and make decision based on what security groups the user belongs to. The below code snippet:

' The below code is for determining Group membership

Set objADSystemInfo = CreateObject("ADSystemInfo")
strUserDN = objADSystemInfo.UserName

Set objUser = GetObject("LDAP://" & strUserDN)
For Each strGroup in objUser.MemberOf
Wscript.Echo strGroup.Name
Next

...gets the following error:

Script: D:\$$Logon_Script\GroupMemberShip.vbs
Line:6
Char:1
Error: 0x80005000
Code: 80005000
Source: Null

So, what doesn't the scripting engine like about:
<Set objUser = GetObject("LDAP://" & strUserDN)>?

I'm running this script on a Win2000Pro machine that is fully patched.

Any and all guidance is gratefully appreciated.

Steve

BaldEagle
04-25-2005, 12:33 PM
I cannot take credit for this, as I found it on another forum:

http://www.visualbasicscript.com/topic.asp?TOPIC_ID=2640

Option Explicit
Dim conn, cmd, rs, temp, ldapPath

ldapPath = "ou=servers,dc=MyComp,dc=com"

Set conn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
conn.provider = "adsdsoobject"
conn.open "active directory provider"
cmd.activeconnection = conn
cmd.commandtext = "<LDAP://" & ldapPath & ">;(objectclass=computer);name,cn,distinguishedname;subtree"
Set rs = cmd.Execute
Do Until rs.eof
WScript.Echo rs.fields("name") & vbTab & rs.fields("cn") & vbTab & rs.fields("distinguishedname")
rs.movenext
Loop

This seemed to fix the problem for the questioner there. Visit the site to see the whole thing in context. Maybe it won't really help you, maybe it will.

Also if you google ldap vbscript you will get lots of hits that may be of more benefit.

BaldEagle