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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distribute vbscript inside a EXE created by WinRAR

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi,

Has anyone gotten creative with packing a vbscript inside a self extracting EXE created by WinRAR? I know vbscripts are self executing just like an exe, but what if the script needed to copy a file? As opposed to mapping to a shared drive surely you could pack both the vbscript and the file to be copied inside the EXE.

I bring this up because a colleague of mine recently showed me how to pack a batch file and screensaver file into a self extracting EXE. The batch handled the copying and the screensaver was right in there with it. May not be practical for every situation, but it got me curious.

Maybe its not a great idea. Just curious what some folks thought.
 
How to turn vbs and js files into exe files from the command line


Any COM Automation programming language (that's all of them but especially VB6 which is what this object was designed for - it also applies to vbscript too).


Use the MS Script Control.


For those that don't have the great VB6 (a member of the same family as vbscript) here's how to make an exe with a script from the command line and notepad.

Create text file on desktop and name it VB2Exe.vb


The Scrpt string variable contains your script.

<code>
Public Module MyApplication
Public Sub Main()
Dim sc as object
Dim Scrpt as string
sc = createObject("MSScriptControl.ScriptControl")
Scrpt = "msgbox " & chr(34) & "Hi there" & chr(34)
With SC
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
End With

sc.addcode(Scrpt)

End Sub
End Module
</code>


Looks fairly familar.

The .NET framework comes with compilers.


You need to make sure the path to the compiler is correct on your windows install.

In an elevated command prompt type


<code>
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:exe "%userprofile%\desktop\VB2Exe.vb"
</code>



Your first VBScript in an exe.



Here's sample vbs code that syntax checks scripts. But the global code does run in the script control. (even though I'm using executeglobal to run it for real).

It runs the vbs script specified against every line in a textstream (Inp) writing it to another textstream (Outp).

Ag(1) is the script to be added. I add extra script to the users script.

You need to define Inp, Outp, and Ag(1).

Note the syntax error checking and messages to the user.

Sub VBSCmd
RawScript = Arg(1)
'Remove ^ from quoting command line and replace : with vbcrlf so get line number if error
Script = Replace(RawScript, "^", "")
Script = Replace(Script, "'", chr(34))
Script = Replace(Script, ":", vbcrlf)
'Building the script with predefined statements and the user's code
Script = "Dim gU" & vbcrlf & "Dim gdU" & vbcrlf & "Set gdU = CreateObject(" & chr(34) & "Scripting.Dictionary" & chr(34) & ")" & vbcrlf & "Function UF(L, LC)" & vbcrlf & "Set greU = New RegExp" & vbcrlf & "On Error Resume Next" & vbcrlf & Script & vbcrlf & "End Function" & vbcrlf
'Testing the script for syntax errors
On Error Resume Next
set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
With ScriptControl1
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.AddCode Script
End With
With ScriptControl1.Error
If .number <> 0 then
Outp.WriteBlankLines(1)
Outp.WriteLine "User function syntax error"
Outp.WriteLine "=========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & .number & " " & .description
Outp.WriteLine "Line " & .line & " " & "Col " & .column
Exit Sub
End If
End With
ExecuteGlobal(Script)
'Remove the first line as the parameters are the first line
'Line=Inp.readline
Do Until Inp.AtEndOfStream
Line=Inp.readline
LineCount = Inp.Line

temp = UF(Line, LineCount)
If err.number <> 0 then
outp.writeline ""
outp.writeline ""
outp.writeline "User function runtime error"
outp.writeline "==========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & err.number & " " & err.description
Outp.WriteLine "Source " & err.source
Outp.WriteLine "Line number and column not available for runtime errors"
wscript.quit
End If
outp.writeline temp
Loop
End Sub

Function NumberScript(Text)
Text = Replace(Text, vbcr, "")
LineArray=Split(Text,vblf)
For i = 0 to UBound(LineArray, 1) - 1

Count = Count + 1
Temp = Temp & vbcrlf & Count & " " & LineArray(i)
Next
NumberScript = Temp
End Function

.
--
 
Also just to package type iexpress into a command prompt and follow the wizard.

Read about it here.


IEXPRESS.EXE is used to create a single self-extracting package from a set of files. Such packages can be used to install applications, executables, drivers, other system components, or setup bootstrappers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top