views:

116

answers:

3

Hi There,

I've been searching the web for a while now and still can't seem to find anything useful on this topic.

What I am trying to create is a button in my Infopath form that will create a user account in Active Directory. The code will need to pull through information stored in the fields of the Infopath form.

I have chosen to use Visual Basic, as I believe that is a good language scripting with AD.

I have successfully run this code:


Sub CTRL1_12_OnClick(eventObj)

MsgBox "Output: "

End Sub

which returns: 'Output: ' in a VB dialogue box when I click on my infopath button. However, when I try:


Set objOU=GetObject("LDAP://OU=People,OU=contoso,DC=contoso,DC=com")

Set objUser=objOU.Create("user","CN=Linda Mitchell")

objUser.Put "sAMAccountName","linda.mitchell"

objUser.SetInfo()

All I get is an error message in Infopath:


The following error occurred:

ActiveX component can't create object: 'GetObject' File:script.vbs Line:14


When I put the same code in to notepad, save as a vbs file and then execute is runs fine and create a user in active directory, what I don't understand is why when I run the same code it doesn't work.

Any ideas?

Thanks Peter

A: 

I would recommend you check out Richard Mueller's web site - he has tons of VBScript code to do all sorts of AD stuff.

Here's a link to a page showing how to create users - is that of help?? I'm not much of a VBScript programmer, but I know Richard's stuff is usually very good and useful.

Here's his entire list of free VBScript code for you to go rummage about!

marc_s
Thanks for that, his website looks pretty good and I may be able to use his code once I find out why this code doesn't work in Infopath but runs fine in a standalone vbs script on my desktop.Peter
McPeter
A: 

I have now found out what the problem was. I needed to set the form to 'full trust' Tools>form options> Security and Trust. I also had to sign the form with my certificate.

Now I am able to run the code from that button.

McPeter
A: 

same problem. Did you get an aswer? Did you solve this issue? Richard

Richard GOTWE
Yes, I found the problem myself and posted the answer.
McPeter