User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 397,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,416 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 4627 | Replies: 10
Reply
Join Date: Jul 2006
Posts: 16
Reputation: nedwards is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
nedwards nedwards is offline Offline
Newbie Poster

Question VBscript in a Visual Basic Application

  #1  
Jul 27th, 2006
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: VBscript in a Visual Basic Application

  #2  
Jul 27th, 2006
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...
Reply With Quote  
Join Date: Jul 2006
Posts: 16
Reputation: nedwards is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
nedwards nedwards is offline Offline
Newbie Poster

Re: VBscript in a Visual Basic Application

  #3  
Aug 4th, 2006
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 )
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: VBscript in a Visual Basic Application

  #4  
Aug 4th, 2006
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....
Reply With Quote  
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 219
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: VBscript in a Visual Basic Application

  #5  
Aug 5th, 2006
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?
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: VBscript in a Visual Basic Application

  #6  
Aug 5th, 2006
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 9:17 am.
Reply With Quote  
Join Date: Jul 2006
Posts: 16
Reputation: nedwards is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
nedwards nedwards is offline Offline
Newbie Poster

Re: VBscript in a Visual Basic Application

  #7  
Aug 5th, 2006
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:
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: VBscript in a Visual Basic Application

  #8  
Aug 6th, 2006
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.
Reply With Quote  
Join Date: Jul 2006
Posts: 16
Reputation: nedwards is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
nedwards nedwards is offline Offline
Newbie Poster

Re: VBscript in a Visual Basic Application

  #9  
Aug 7th, 2006
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.
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

Re: VBscript in a Visual Basic Application

  #10  
Aug 21st, 2006
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 11:25 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 6:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC