Embedding VBScript in a VB6 Application 
Author Message
 Embedding VBScript in a VB6 Application

Greetings, folks...

I'm looking to see if this can be done -- I work in a 500 pc environment
and I'm trying to embed VBScripts into a VB6 application to make it a
bit more user friendly to the SysOps as well as the other admin.  I've
seen several topics regarding this saying how the syntax is almost the
same, however, I haven't seen too many examples or inclusions that are
required -- so here are two questions...

1) Do any references or components need to be added into the VB6 Project
in order to recognize the VBScript Code?

2) Could someone please write an example of a simple WMI/WSH script that
would, for instance, pull the serial number and video adapter from a
remote machine?

With those two questions answered, I think it would be fairly easy for
folks who commonly ask this question to begin designing their application.

Rob



Wed, 27 Jul 2005 22:31:44 GMT  
 Embedding VBScript in a VB6 Application
A couple of comments inline..,

Quote:
> Greetings, folks...

> I'm looking to see if this can be done -- I work in a 500 pc environment
> and I'm trying to embed VBScripts into a VB6 application to make it a
> bit more user friendly to the SysOps as well as the other admin.  I've
> seen several topics regarding this saying how the syntax is almost the
> same, however, I haven't seen too many examples or inclusions that are
> required -- so here are two questions...

VBScript syntax and grammar is indeed almost identical, with VBScript being a
small subset of VB in terms of keywords and (roughly) in terms of structures.

Quote:
> 1) Do any references or components need to be added into the VB6 Project
> in order to recognize the VBScript Code?

If you're wanting to dynamically interpret and execute VBScript code, you need
to host it somehow first, exposing some objects within your application
properly.  Normally this is done by embedding the Microsoft Script Control
(msscript.ocx) and importing the objects from your application into the Script
Control's spaces using its AddObject method.  Once you do that, ANY Active
Scripting language is automatically embeddable at runtime - makes it very nice
for "choices".

Quote:
> 2) Could someone please write an example of a simple WMI/WSH script that
> would, for instance, pull the serial number and video adapter from a
> remote machine?

There are several examples of this findable in the Google archives here, but
before we go into that, le me point out something important.

If you want a generic WSH-hosted VBScript example, that's pretty easy given some
basic info about the target machine.  It is comletely un-necessary to host it in
your application, though - if WSH and WMI are available, VBScript can be
executed directly.

Here's a generic example of a VBS file which returns the video display
information:

set locator = CreateObject("WBEMScripting.SWBEMLocator")
set wmi = locator.ConnectServer()

' if you want to find out on a remote mashine, you would do like :
' set wmi = locator.ConnectServer _
'("<servername>","root/cimv2","<user>","<Password>")

set Properties = wmi.Get("Win32_VideoController")
for each oProp in Properties.Instances_
 WScript.Echo oProp.Name
next

Quote:
> With those two questions answered, I think it would be fairly easy for
> folks who commonly ask this question to begin designing their application.

> Rob



Thu, 28 Jul 2005 02:03:17 GMT  
 Embedding VBScript in a VB6 Application


Quote:
> A couple of comments inline..,


> If you're wanting to dynamically interpret and execute VBScript code, you need
> to host it somehow first, exposing some objects within your application
> properly.

If this leaves you going, "Huh?" post back - this sounds very bizarre to people
at first, but there are reasons for how it works.

Quote:
> Here's a generic example of a VBS file which returns the video display
> information:

Stolen from an old Torgeir Bakken post, FYI. ;)


Thu, 28 Jul 2005 02:06:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Embedding VBScript in a VB6 Application

2. Sharing Violation in VB6 IIS Applications

3. VB6 Web Applications

4. Scripting and my VB6 application

5. VBScripting in a VB6 Application

6. Printer driver for embedded application

7. Difference among VB6, VBA, VBScript ?

8. Creating/Querying Scheduled Tasks from VB6/VBScript

9. VBscript with VB6

10. Using the VBScript RegExp object in VB6

11. Using VBScript 5.1 RegEx object in VB6?

12. Can I use VB6 IDE for VBScript editing?

 

 
Powered by phpBB® Forum Software