Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VBScript to VB exe 1

Status
Not open for further replies.

gkbren

MIS
May 1, 2003
13
US
I know this isn't the forum for Visual Basic, but I have a VBScript that adds address information to the active directory. I am trying to use that script in a visual basic program (reading from one source and writing to AD). However, it crashes on the "set objUser = GetObject" line of the program. Can anyone tell me why? Am I missing a reference?

Here's part of the code:
'strADldap = "CN=Big Bird,OU=SS Users,DC=sesame,DC=net"
strADldap = "LDAP://" & strADldap
Set objUser = GetObject(strADldap)
objUser.Put "streetAddress", strADArray(3)
objUser.SetInfo
 
[blush]It was just pointed out to me that the step where the code is bombing is not the "Set" line but the "put" line:

objUser.Put "streetAddress",strADArray(3)

Any suggestions?
 
Might help to have more info.

"Crashes." What does this mean? Is there a specific error code?

objUser. How was this declared in the VB program?
 
The error code is "Run time error '-2147467259 (800040050)' Automation error, unspecified error"

I think the declaration is where I have the problem. The VBScript that I used did not declare the variable other than "Set objUser = GetObject(strADldap)", and it ran fine.

I'm having trouble finding information on VB for this. An article from 1999 had a suggestion:

DIM objUser as IADsUser

I added this, and now my program no longer "breaks/crashes" when it encounters the PUT statement. :)
But now it breaks at the objUser.SetInfo line :-(

Any help would be welcome.
 
Oops--forgot to include the new error code for the break for objUser.SetInfo

Runtime error '-2147016693(8007200b)'
Automation error
The attribute syntax specified to the directory service is invalid.
 
Have you tried
Code:
Dim objUser As Object
yet?

I don't have a clue what reference you'd add to a VB program to use early binding. It may be the "Active DS Type Library" but I don't have any experience with it. Have you added this reference and tried it out?

I'd guess you have.

From the error you are getting most recently I'd have to assume you have a syntax error as it says. Not being LDAP-literate I don't know what it might be though.
 
In your initial post, you have

'strADldap = "CN=Big Bird,OU=SS Users,DC=sesame,DC=net"
strADldap = "LDAP://" & strADldap

Due to the single-quote commenting the first line, you would attempt to bind to "LDAP://" which would throw the "Automation Error".

Since you say it now gets beyond this point, I'll presume you resolved this. What does strADArray(3) contain?

Dilettante, that is the correct type library.

Jon Hawkins
 
Sorry, posted prematurely.

If strAdArray(3) contains an empty string, you'll get the "The attribute syntax specified..." error. You'll need to add at least a single blank space.

objUser.Put "streetAddress"," "

Jon Hawkins
 
Thanks to everyone that replied. I tried taking out the array variable, and replaced it with strTEMP, which I forgot to declare. Believe it or not, it worked. Here's the code snippet:
Public strADArray(16) As String
Public strADldap As String
Sub Works()
strADldap = "LDAP://CN=Big Bird,OU=SS Users,DC=sesame,DC=net"
Set objUser = GetObject(strADldap)
strTEMP = strADArray(0)
objUser.Put "company", strTEMP
objUser.SetInfo
End Sub

I went back and redefined strADArrary(16) as Variant, and it worked. Does anyone have any insight? Again, I know this is not VBScript, but there seem to be more VBScripters familiar with ADSI than VB programmers.

Thanks again--
(Special thanks to Jon Hawkins--I think this answered why using strADArray(2) bombed when I tried the whole code string)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top