Solved

VB Scripting - New and need help!

Posted on 2007-03-29
14
150 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:jsctechy
  • 6
  • 6
  • 2
14 Comments
 
LVL 13

Expert Comment

by:rettiseert
ID: 18818174
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
0
 
LVL 13

Expert Comment

by:rettiseert
ID: 18818187
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18818344
thanks for the replies.
I see some stuff about Cscript, WSH also.
Using VB Scripting, can you call WSH?  Or am I totally lost?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18818503
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...
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18818578
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?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18818606
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!
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18818663
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"
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 67

Expert Comment

by:sirbounty
ID: 18818801
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...
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18818911
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?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18819015
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...
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18819185
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.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18819208
Then I'd suggest you grab the download the HSG archive...http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx
Great info on AD queries! :^)
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18819285
cool, thanks a lot.  I'll look into all this information.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18819325
Happy to help - thanx for the grade! :^)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now