Link to home
Start Free TrialLog in
Avatar of jsctechy
jsctechyFlag for United States of America

asked on

VB Scripting - New and need help!

Hi all,
I have a quick question for you guy, but need an answer to quickly.  I am wondering what I will need to start making some VBSCRIPTS.  What program will I need?  Also, what program(s) do the client computers that are running these scripts require?

My goal is to run these VB scripts on client machines so I don't have to manually configure specific settings.  I've done most in batch, but want to move over to VB.  I don't know the first thing about VB, but will try to learn some as I go along.

Please help me if you can.

Thanks,
JSCTECHY
Avatar of rettiseert
rettiseert

If your computer has Internet Explorer 5 or above you already have all you need to run VBS.

As a bat file, you just need to edit a text file with your code but use the extension VBS, the double click the icon and the code will run
Avatar of jsctechy

ASKER

thanks for the replies.
I see some stuff about Cscript, WSH also.
Using VB Scripting, can you call WSH?  Or am I totally lost?
Avatar of sirbounty
JSCTECHY, most Microsoft clients will run vbscripting/wsh scripts (basically these are the same).
You create a script using a text editor - notepad, for example.

Wscript.echo "Hello"

is all you need to write your first script.
Of course, you can get fancy with it, as you learn.
The clients will be able to run it - but here's the difference:
There are 2 methods for calling a vbscript:
1) Cscript.exe - this is useful when you want the above .echo to simply write some text on screen - not generate a popup.  There's not a lot of difference between the two methods outside of this.
1) Wscript.exe - this is the default method and if cscript is not explicitly used, this will be.  It's, obviously, the method used if you double-click on a script as well.

The only other thing required is to name the script.  .VBS is usually the extension, but you can use .VBE, among others...
Sirbounty,
I understand what you mean.  But when you write batch, you can always do a /?, is there something you can use to do that w/ VB Scripting, or do I just reference a help site?
google is your friend there.

Fortunately, you'll get 'some' indication when you attempt to code and it's not quite right...it'll tell you at least what line # the error is on.

You can get better quality errors by using

On Error Resume Next
at the head of your code and then

wscript.echo err.Description
after whereever you expect an error - for whatever reason.

But no, there's no context help for the commands....

Activeexperts.com and the scripting guy at Microsoft are two of my favorite sites for help!
Thanks for the info-
One last thing..  In the code below, what is it saying? I know it will run 'notepad.exe', but why all the additional text?

dim wshshell
set wshShell = Wscript.CreateObject("Wscript.Shell")
wshshell.Run "notepad.exe"
Well - the first line is just for clarity (and better coding practive):
You're 'declaring' that somewhere in the following code, you will be using that variable.
The second line is the one that uses it - and assigns it to an object reference to the wscript shell method.
The last simply uses that object reference to run an external file...
I see.  So I can do something like this:

On Error Resume Next
dim Runprog
set RunProg = wscript.CreateObject("wscript.Shell")
Runprog.Run "\\Jsfs1\APPS\OFFICE2003\OFFICE\setup.exe PIDKEY=XXXXXXXXXXXXXXXXXXXXXXXXX
USERNAME=Setup COMPANYNAME="Name." /qb"

When in batch I was doing this:

\\Jsfs1\APPS\OFFICE2003\OFFICE\setup.exe PIDKEY=XXXXXXXXXXXXXXXXXXXXXXXXX USERNAME=Setup COMPANYNAME="Name" /qb

It seems like there is way more text when using the VB.  But as you get more advanced later on, Batch just doesn't cut it, correct?
Well - I'm not going to be snared into that one...cause I know of a few DOS batch experts that would be quick to jump on me!! :^)

But, sometimes it's just the oppoosite..it really depends - I still use batch scripts for 'small' stuff...and if 'all' you're doing is using the shell for running a program, I don't see a need to use vbs anyway...

But for the above - the problem you'll run into is your use of the quotes:
When they're needed by the 'shelled' app, you'll need to put them in there, else it'll fudge the whole Run line...see here:  Chr(34) is one way for doing this:

Runprog.Run chr(34) & "\\Jsfs1\APPS\OFFICE2003\OFFICE\setup.exe PIDKEY=XXXXXXXXXXXXXXXXXXXXXXXXX
USERNAME=Setup COMPANYNAME=" & chr(34) & "Name." & chr(34) & " /qb"

You can also double-up on the quotes to accomplish the same thing...
Sir,
I am just running programs for now until I can get used to how things work.  I'll eventually want to create IP ports and add printers based on AD groups.  Also would like to automate some tasks.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cool, thanks a lot.  I'll look into all this information.
Happy to help - thanx for the grade! :^)