Create a user in Active Directory from an Infopath form - vb6

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.

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!

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.

Related

Google sheet script access lost after new API - error trying to use Tools -> Script editor

I have just returned to do some maintenance on Google sheet scripts I wrote last year and I can't get in to debug them from the Sheet's Tools -> Script editor command. When I try, Google opens up the standard "Access Denied" - "Request Access" error page. The same problem seems to affect every Sheet I have with an embedded script. I suspect this is a side-effect of being upgraded to the new scripting API.
I can still run the scripts normally and they operate as expected.
I can open the scripts from the new API Console and I can edit them successfully from there. However if I try to run the scripts with the debugger from the API console, I get an immediate error when the script tries to access the Sheet data it looks like the SpreadsheetApp.getActiveSpreadsheet is not returning a useful value (debugger says "select active spreadsheet first"). I would guess that the same problem that prevents the Script editor working from the Sheet is also preventing the API debugger working properly.
I am sure the code itself is fine as it works without the debugger.
Surprisingly, just after posting this question I seem to have found the answer.
It appears that the Google Sheet's Tools -> Script editor command used my default (home) Google account, even though I was logged into my work account and had successfully loaded the Sheet which I can only access from my work account.
Problem resolved by logging out of both my Google accounts and logging back in with my work account. I think this must be some sort of Google Bug.

Outlook form VBScript won't run

I'm designing a Outlook Contact form. None of the sample code I've tried to put in the View Code button's Script Editor does anything. The most basic example is:
Sub Item_Open()
msgbox "Hello World"
End Sub
When I click the Run This Form button, no message box or error message appears. It seems to totally ignore the VBScript. The same thing happens with every bit of sample code I've tried.
This is my first time doing any development for Office or in VBA or VBScript, so I assume I'm missing something basic, but I've watched and read a few tutorials, doing exactly what was shown and nothing works. I can design and publish a Contact form with custom fields and and basic combo boxes.
In the Trust Center I have Macro Settings set to "Notifications for all macros" and the Email Security options "Allow script in shared folders" and "Allow script in Public Folders" are both checked.
I'm designing a Contact form using Office 365 32-bit Version 1708 (Build 8431.2079 Click-to-Run) Monthly Channel on Windows 10 x64 Version 1703 Build 15063.608.
Any help would be greatly appreciated!!
Thank you!
The solution was to add some registry keys as described in the 2 articles below.
Custom form scripts now require registry settings to be added.
https://support.office.com/en-us/article/Custom-form-script-is-now-disabled-by-default-bd8ea308-733f-4728-bfcc-d7cce0120e94
https://www.slipstick.com/outlook/custom-form-security/
The registry settings mentioned there fixed my issue.
Possible causes:
VbScripting is not enabled on your machine, disabled there in Registry, especially on Windows 10. You have to enable there.
Though VbScript is enabled and you can run scripts directly from a file in a Folder like sample.vbs, script may not run on Outlook Custom Form if Outlook application has security setup in Registry Key when installed.
I faced this problem and solved after several attempts.

VBS script issue loading a IE frame without address bar

I've got a very strange issue.
I'm trying to open a URL through Citrix called through a VBS script.
Here is the code:
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.ToolBar=0
oIE.Navigate("https://example.com/sites/example/SitePages/Home.aspx")
oIE.Height=800
oIE.Width=1500
oIE.Left=0
oIE.Top=0
Do While (oIE.Busy)
Loop
oIE.Visible=1
This loads fine for most users but on two specific users the script fails to work and just displays the command prompt. At that point no other user can load the script until that user either closes the command prompt or waits for it to time out.
I'm calling the script using the following:
c:\windows\system32\cscript.exe \\servername\share\script.vbs
I tried copying the user accounts so they have the same permissions but it loads fine on the test account.
I'm trying to achieve a URL 'published application' which loads an IE frame with address bar. If there's a better solution than the above code please let me know.
I have seen an error once which said it failed to call InternetExplorer.application
Hope this helps.
Kind Regards,
Scott
Resolved the issue :)
Turned out that the Internet explorer browsers for each user needed resetting to defaults, this sorted the issue for both users.
Hope this information helps someoene.
Scott

FileOpenDialog from vbScript custom action appears behind main dialog

I'm creating an installer at work that must open a file browser. There is no file browser in wix, so I built a custom vbscript action that uses the Shell.BrowseForFolder method. It's working fine, but the file dialog shows up behind the main wix window. Does anyone know a wix/vbscript approach I could take to solve this problem?
Locate the HWND for the MSI UI and pass this into Shell.BrowseForFolder. I see a few example solutions that use FindWindow("MsiDialogCloseClass", vbNullString). Be careful about launching UI from a custom action: you need to consider silent installs/repair/uninstall, etc to make sure you get it right in all cases.
It looks like you're trying to allow the user to pick a directory. MSI has native support for this. I reccomend you use that. For an example see http://wix.codeplex.com/SourceControl/latest#src/ext/UIExtension/wixlib/BrowseDlg.wxs.

VB6 IE frame / WebBrowser causing NT.dll error

We have a legacy VB6 application which has worked just fine on Windows XP Professional SP 3 until just recently when we added an IE frame control so that we could display static local HTML files on a form. And, it works fine until I go to close the application. And, then it reports the following error message (consistently):
Faulting module ntdll.dll, version 5.1.2600.5755, stamp 49901d48
Here's the reference in the Visual Basic project file:
Object={EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0; ieframe.dll
And we use it by performing the following actions:
Development machine is running Win7 + Vb6 IDE.
Add a component reference to the "Microsoft Internet Controls" located at C:\Windows\SysWow64\ieframe.dll
Place a control on the form at design time.
Show that form modally by calling Form.Show vbModal The error happens when I use the default form instance frmMyForm.Show vbModal as well as when I use a local instance Dim MyForm as New frmMyFormMyForm.Show vbModal
Call WebBrowser.Navigate "staticPage.html"
When the user presses a button, the button click event returns the user choice and the form is disposed of.
Exit the application -- Here's where I get the error.
I've been looking all over the web, and haven't been able to find a whole lot of people still trying to use VB6 in this way. So, I'm wondering if someone might be able to help me on stackoverflow. Any help is much appreciated!
[Update] And, the plot thickens. I made a sample application with just that web component in order to make sure that it was causing the error. But, I didn’t experience the error when it closed like I was when exiting our existing/legacy vb6 application. I'll do a bit more investigating.
A follow up to this in case any runs into the same issue (the original poster and I were coworkers at the time)...
The application was using the VBCorLib library, and some of its string manipulation classes utilized direct memory access incorrectly. Read more at this VBCorLib forum post.
It turns out that the issue was that I was trying to delete the temporary file that the browser had loaded. It works now that I've moved that delete file code to the form unload event.

Resources