Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to convert a VBscript.vbs into an EXE? 1

Status
Not open for further replies.

tatin

MIS
Apr 14, 2004
29
LC
I have written a Vbscript.vbs and needs to compile it into an EXE. Someone can easily modify the script file with a text editor.


Any help?
 
Well put it into VB and compile it. Do you have a copy of regular VB?
 
No. I have Visual C++ 6.0 but don't know much about its language.


If I could get the C++ Syntax to run the script from within a C++ EXE, I am in business. I have been trying at customizing a simple C++ project but I need the code lines that runs the script....
 
Thats a good way to do it if the only reason you need an EXE is to keep peeps from changing your source.

I give you a star!
 
Thanks PH, but I would also want to start my app with an EXE, it is more 'professional' I would say.
 
it is more 'professional'
So, use professional tools ;-)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Either translate it into C or beg/borrow/steal a VB compiler.
 
Thanks Guys, I succeeded in creating an EXE that runs the VBscript.

My Trouble now is to Encode the Script. I can't get it to be 'baked' in the EXE that I have created in C++.

Neither can I get a nice icon for my created C++ EXE. I will forego this in the mean time.
 
Just to know, what are you doing in VBS you can't do in C++ ?
 
You can also create the script on the fly with the executable you wrote, spawn wscript.exe to run it, then delete the script file.

You can also check out Free Basic Scripting Language, which is a free scripting language similar to Basic that has a compiler in it. It has its own file handling functions built in. Variable naming is similar to the old BASIC style, with % and $.

Lee
 
Another option that might meet the need is to write most of the logic as an ActiveX control (OCX) in VB5CCE, then host the control in an HTA. I don't recall if it can create ActiveX DLLs, but if it can you might then host these in WSH scripts too.

This would allow most of the logic to be presented in compiled form, without the need to rewrite it in a radically different language. An HTA can't have an embedded icon like an EXE can, but it can indeed have an icon that appears in the window's title bar and the Windows Task Bar. You can always use that icon as a shortcut icon as well.

VB5CCE was once hosted as a free download by Microsoft, and was also included on companion CDs packaged with many books. I'm not sure about 3rd-party sources of VB5CCE downloads now - they may not be considered "legit" even though this was always a free product. I'd be careful to virus-scan any such files from 3rd party sources. They may also omit the Help file downloads that belong to the VB5CCE distribution.

I see one possible source at Visual Basic Game Programming With DirectX but I can't vouch for it.
 
Great!

I was under the impression it was gone, like Microsoft's FTP site and most DOS-related downloads.

Thank you for correcting my error, tsuji.

I can't seem to find the documentation (help) files for this product except at Microsoft's Japanese downloads. I did find a couple of "fixes" and such:

VB5CCE FAQ
Visual Basic 5.0 Control Creation Edition : Picclip Update Module
VB5cli.exe Fixes Visual Basic 5.0 Control Installation Problem

That's about all I dug up though, aside from:

Service Pack 3 - Readme which may not install with VB5CCE since it was for Pro and Enterprise.
 
I tried VB5CCE on a "clean" system, a Windows 95 installation that never had any developer tools on it.

I started with a small script:

Jabber.vbs
Code:
Option Explicit

Function Jabber()
    Const ForReading = 1
    Dim FSO
    Dim strIn
    Dim tsIn
    Dim strOut
    Dim tsOut
    Dim strLine

    Set FSO = CreateObject("Scripting.FileSystemObject")
    strIn = InputBox("File to Jabber")
    If StrIn = "" Then
	Jabber = True
        Exit Function
    End If
    strOut = InputBox("New jabbered file")
    If strOut = "" Then
        Jabber = True
        Exit Function
    End If
    Set tsIn = FSO.OpenTextFile(strIn, ForReading)
    Set tsOut = FSO.CreateTextFile(strOut, True)
    Do Until tsIn.AtEndOfStream
        strLine = tsIn.ReadLine
        strLine = Replace(strLine, "a", vbFormFeed)
        strLine = Replace(strLine, "e", "a")
        strLine = Replace(strLine, "i", "e")
        strLine = Replace(strLine, "o", "i")
        strLine = Replace(strLine, "u", "o")
        strLine = Replace(strLine, vbFormFeed, "u")
        tsOut.WriteLine strLine
    Loop
    tsOut.Close
    Set tsOut = Nothing
    tsIn.Close
    Set tsIn = Nothing
    Set FSO = Nothing
    Jabber = False 'No cancels.
End Function

WScript.Echo "Start!"
If Jabber() Then
    WScript.Echo "Canceled!"
Else
    WScript.Echo "Done!"
End If
Then I started up VB5CCE and created an ActiveX control project. I named the project [tt]Jabber[/tt] and the UserControl [tt]Compiled[/tt].

Next I copied in the VBScript code for the function [tt]Jabber()[/tt] into the UserControl's code window. Because VB5 did not have the [tt]Replace()[/tt] function yet, I faced a decision.

One way would be to write my own [tt]Replace()[/tt] using the string functions already in VB5. The other is to write a function in the calling script that invokes VBScript's [tt]Replace[/tt], and pass the calling script to the VB5 version of [tt]Jabber()[/tt] as an Object, then invoke the function from the script as a method.

I chose the latter, and I called my [tt]Replace()[/tt] wrapper function [tt]R()[/tt].

Here is the VB5CCE code:

Compiled.ctl
Code:
Option Explicit

Public Function Jabber(ByVal Caller As Object)
    Const ForReading = 1
    Dim FSO
    Dim strIn
    Dim tsIn
    Dim strOut
    Dim tsOut
    Dim strLine

    Set FSO = CreateObject("Scripting.FileSystemObject")
    strIn = InputBox("File to Jabber")
    If strIn = "" Then
        Jabber = True
        Exit Function
    End If
    strOut = InputBox("New jabbered file")
    If strOut = "" Then
        Jabber = True
        Exit Function
    End If
    Set tsIn = FSO.OpenTextFile(strIn, ForReading)
    Set tsOut = FSO.CreateTextFile(strOut, True)
    Do Until tsIn.AtEndOfStream
        strLine = tsIn.ReadLine
        strLine = Caller.R(strLine, "a", vbFormFeed)
        strLine = Caller.R(strLine, "e", "a")
        strLine = Caller.R(strLine, "i", "e")
        strLine = Caller.R(strLine, "o", "i")
        strLine = Caller.R(strLine, "u", "o")
        strLine = Caller.R(strLine, vbFormFeed, "u")
        tsOut.WriteLine strLine
    Loop
    tsOut.Close
    Set tsOut = Nothing
    tsIn.Close
    Set tsIn = Nothing
    Set FSO = Nothing
    Jabber = False 'No cancels.
End Function
Not much has changed here from the original VBScript version. I saved the project and compiled it, which registers the new Jabber.ocx on that machine in passing.

Then I slightly rewrote the calling script:

Jabber Compiled.vbs
Code:
Option Explicit

Dim Jabber

Function R(ByVal Expression, ByVal Find, ByVal ReplaceWith)
    R = Replace(Expression, Find, ReplaceWith)
End Function

WScript.Echo "Start!"

Set Jabber = CreateObject("Jabber.Compiled")
If Jabber.Jabber(Me) Then
    WScript.Echo "Canceled!"
Else
    WScript.Echo "Done!"
End If
Set Jabber = Nothing

The results:

orig.txt
Code:
this is some text to be converted to
jabbering by the script Jabber.vbs

it should look very strange after it
has been rendered into pure jabber
by the Jabber script.

always rely on Jabber for the finest
in jabbering!

jabbered.txt
Code:
thes es sima taxt ti ba cinvartad ti
jubbareng by tha scrept Jubbar.vbs

et shiold liik vary strunga uftar et
hus baan randarad enti pora jubbar
by tha Jubbar scrept.

ulwuys raly in Jubbar fir tha fenast
en jubbareng!
The only deployment issue is making sure that the VB5 runtime is installed on target machines, and that Jabber.ocx gets copied and registered, such as by running:

[tt] regsrv32 {path}Jabber.ocx[/tt]

This can be done from a command prompt or Start|Run dialog. One could also create an OCX installer package, etc.

I think this is as close as you can get "for free" to compiling VBScript. One might replace the calling script by using some free compiler for a language that supports ActiveX objects. Then you'd have a 100% solution.

You can also easily use things like the Common Dialog control in VB5CCE to provide a nicer file dialog than you get by using [tt]Inputbox()[/tt]. Adding a reference to the Microsoft Scripting Runtime lets you use early binding and defines the FSO constants, and for that matter you can use typed variables for better performance.

If the script does a lot of work, rewriting it as an ActiveX control like this may increase performance generally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top