Hello,
I need help. I have been searching the web to try and find to somehow add vbscript in my visual basic application. I'm not sure how to go by doing that.

What I'm really trying to do is to use visual basic as a GUI and then use vbscript to add a user to the active directory. I saw that you could use a script engine in visual basic but that hasn't been working for me.

HELP!! PLEASE!!!:eek:

You should be able to use createobject, and create the object in question.... for example:

dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.run "c:\windows\notepad.exe", 1, 0

Which should create the WScript Shell object, and then launch it's "run" method to spawn notepad...

Ok,

This helped me get a start on this. So this is what I have so far. I have a form in Visual Basic which calls this:

Private Sub btnClickMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClickMe.Click
        Dim wsh
        wsh = CreateObject("WScript.Shell")
        wsh.run("C:\Scripts\test.vbs", 1, 0)
    End Sub

And then under the folder Scripts i have this for my vbscript

Wscript.echo "My very first script."

This all works fine, but what's say I wanted to replace "My" with my name. I would have a textbox on my form and then when I click on the button it would send what I entered into the text box infront of " very first script." Is that too much to ask?;)

If my spelling/grammar is not right it is because I'm slowing loosing blood from my thumb. ( Potato peeling accident )

Yikes on the thumb....

Firstly, I want it to be known clearly that you are NOT using Visual Basic.... the used the same name, but it's actually .NET or express, but not legacy VB. The Forum that you are posting in, is for Visual Basic from 6 and below.... you are using .NET.
Your question, however, is related more to the concept of programming than to a specific language, so I'm not going to move the thread. I don't remember exactly if .NET's textboxes use the .text property, or the .value property, but I'll post code for both. One problem that you are going to face is the fact that the script file, IS NOT part of your program, which means you will either have to pass it parameters, OR you'll have to set an option somewhere that the script reads when it runs.

The two ways are basically like this, to pass the parameter:
you would set the vbscript file up to read whatever is passed it on the command line, just like if you click start, go to run, and type in: notepad hello.txt you'll see notepad do something out of the ordinary.... if hello.txt does not exist, notepad will ask you if you want to create a new file. You can make your VBScript program take parameters also, so you could call it with something like:
myscript.vbs jerry
and then it would use jerry as the input to display in the echo command.

The other method, would be to have the VB.Net Program write a value somewhere, like in a file, or in the registry, and then make the script program actually read that value from the file or registry, and act accordingly....

Firstly, I want it to be known clearly that you are NOT using Visual Basic.... the used the same name, but it's actually .NET or express, but not legacy VB.

I'm curious how you can tell with the information nedwards gave. I see nothing mentioning any version of anything...

I'm also curious why in a VB application someone would want to use VBScript? Why not just use VB?

Private Sub btnClickMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClickMe.Click is a declaration type that is only acceptable in a .NET layout. The parameters passed are system event objects (system.object, system.eventargs) which doesn't exist in legacy VB, and beyond that, the "handles" keyword for the event doesn't exist in legacy VB. Those are strictly used in .NET or VB Express (which is actually .NET also).

As for his motivation..... who knows, maybe he's calling a script that someone else made, and doesn't want to try to port the entire thing..... we will only know if he chooses to answer that question.

Well that sure answers a lot of unasked questions. I knew something didn't seem right when I downloaded VB express. I only know how to programing in VB 6.0 not .Net.

I'm trying to program in VB 6, but I didn't want to purchase it just to do this one project. I would like it to just do it all in VB and not use VBscript cause that is just starting to confuse me cause VB 6, .Net, and VBscript almost look the same to me. My questions is could I control the active directory with VB? If so is there any good material about this on the internet?

For example add a user and delete a user. Even move a user from one OU to another OU.

Thanks :cheesy:

I don't see why you can't just port over the code that's in the VBScript WSH. If you send me (or post the code) to the .VBS, I can show you how to import it into VB. Since you are using express, there may be minor touch up details that you'll have to fix, but the basis will be solid.

Well the thing is that I haven't coded anything yet. I was just doing some research before I start coding and find out that I wasted all my time in VBscript or Visual Basic, but this is what I want to do:

1. The user will enter and select all appropriate fields.
2. The user will select the “ADD USER” button.
3. A data validation check will be run to ensure that all fields have data in them. If any field is missing data the program should terminate with an error telling the user that “One or more fields is missing data.” And then bring them back to the main screen to fix the error and try again.
4. The program will use the AD Admin credentials supplied to add the user to the selected domain “SELECT THE DC FOR NEW USER” with a standard user profile and the “Description field” being filled with what the User had entered in the “ENTER A DESCRIPTION FOR THE NEW USER” field.
5. The program will then add the newly created user to all the groups that were selected in the “SELECT GROUPS FOR USER” area.
6. The program will then assign a password of “ecare01” that is a Zero not an O. Also, the option of “Force user to change password at next login” will be enabled.
7. Using the E-mail admin credentials supplied the program will then log into the appropriate mail server. This will be determined by the domain selected.
8. At the end of the script. Any errors reported during the creation of the user will be output to the screen with descriptive error messages.
9. The program will bring the user back to the beginning.

Hello,

Hey Nedwards, if you don't want to use VB2005 and would like to use legacy VB you can get to a VB editor within Excel (if you have Excel). Just my $0.02.

I don't see why you can't just port over the code that's in the VBScript WSH. If you send me (or post the code) to the .VBS, I can show you how to import it into VB. Since you are using express, there may be minor touch up details that you'll have to fix, but the basis will be solid.

Still doing the port assist? I am new to VB/VB.NET. Working with an express edition at the moment for edu./testing purposes. I have a script that creates an outlook message and some various other things, but it has reached its limitations as far as vbs goes....I need something a little more powerful so that I can get the complete features out of it but dont want to reinvent the wheel either. What do I need to do to import?

This article has been dead for over six months. Start a new discussion instead.