943,925 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jul 27th, 2006
0

VBscript in a Visual Basic Application

Expand Post »
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:
Similar Threads
Reputation Points: 13
Solved Threads: 0
Newbie Poster
nedwards is offline Offline
16 posts
since Jul 2006
Jul 27th, 2006
0

Re: VBscript in a Visual Basic Application

You should be able to use createobject, and create the object in question.... for example:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim wsh
  2. Set wsh = CreateObject("WScript.Shell")
  3. 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...
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 4th, 2006
0

Re: VBscript in a Visual Basic Application

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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btnClickMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClickMe.Click
  2. Dim wsh
  3. wsh = CreateObject("WScript.Shell")
  4. wsh.run("C:\Scripts\test.vbs", 1, 0)
  5. End Sub

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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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 )
Reputation Points: 13
Solved Threads: 0
Newbie Poster
nedwards is offline Offline
16 posts
since Jul 2006
Aug 4th, 2006
0

Re: VBscript in a Visual Basic Application

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....
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 5th, 2006
1

Re: VBscript in a Visual Basic Application

Quote originally posted by Comatose ...
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?
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,738 posts
since May 2006
Aug 5th, 2006
0

Re: VBscript in a Visual Basic Application

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.
Last edited by Comatose; Aug 5th, 2006 at 10:17 am.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 5th, 2006
0

Re: VBscript in a Visual Basic Application

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:
Reputation Points: 13
Solved Threads: 0
Newbie Poster
nedwards is offline Offline
16 posts
since Jul 2006
Aug 6th, 2006
1

Re: VBscript in a Visual Basic Application

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 7th, 2006
0

Re: VBscript in a Visual Basic Application

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.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
nedwards is offline Offline
16 posts
since Jul 2006
Aug 21st, 2006
0

Re: VBscript in a Visual Basic Application

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.
Last edited by cyman73; Aug 21st, 2006 at 12:25 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Change password for admin
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Randomize generate massive user name database?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC