How can I turn a script into an executable ?

J

JAQK

I have a .vbs script that I can run from the command line without a problem.
(simply using 'cscript script.vbs')

I don't know what syntax to use in order to properly create some sort of
batch file which I could then run by double-clicking or using the task
scheduler.

If I just copy and paste the syntax text from the command line window, it
will not work in a batch file, so I know I'm doing something wrong.

Thanks in advance.
 
D

Dennis Glover

From a command-line window:

"help start"
-or-
"start /?"

The command line _is_ your friend!
 
P

Pegasus \(MVP\)

JAQK said:
I have a .vbs script that I can run from the command line without a problem.
(simply using 'cscript script.vbs')

I don't know what syntax to use in order to properly create some sort of
batch file which I could then run by double-clicking or using the task
scheduler.

If I just copy and paste the syntax text from the command line window, it
will not work in a batch file, so I know I'm doing something wrong.

Thanks in advance.

Use this syntax:

WScript.exe NameOfScript.vbs
 
S

Steve Parry [MVP]

JAQK said:
I have a .vbs script that I can run from the command line without a
problem.
(simply using 'cscript script.vbs')

I don't know what syntax to use in order to properly create some sort
of batch file which I could then run by double-clicking or using the
task scheduler.

If I just copy and paste the syntax text from the command line window,
it will not work in a batch file, so I know I'm doing something wrong.

Thanks in advance.

You cannot compile a script because it takes the run-time engine to
interpret the code.

You can encode the script by way of the Windows Script Encoder, look for
the encoder on the MS script site.

http://www.microsoft.com/mind/0899/scriptengine/scriptengine.asp

It's not 100% secure but will keep most users from modifying or viewing
the code.
 
J

Joe_E

A workaround is to use the iexpress.exe tool that ships with Windows
(2000 & beyond).
This tool allows you to create an EXE made up of a number of source
files into a single EXE.

Steps:
Let's assume you want to create myScript.exe that runs myScript.vbs
when a user double-clicks on the file (myScript.exe). Let's assume
further that you want myScript.vbs to be run using Cscript.exe as the
scripting host

* make sure that your script file name is in the short name format
(i.e. no longer that 8 characters and contains no spaces -->
myscript.vbs and not --> my script sample.vbs)
* create a batch file to run myScript.vbs and save this to the same
directory as myScript.vbs. See batch file for this is at bottom of this
thread
* From the start menu type IEXPRESS and select RUN
* When the IEXPRESS WIZARD pulls up select 'Create New self extracting
directive' and click NEXT
* On the PACKAGE PURPOSE screen select 'Extract files and run an
installation command' and click NEXT
* On the PACKAGE TITLE screen enter a descriptive name and click NEXT
* On the CONFIRMATION PROMPT select whether or not you want a prompt to
be shown to users before running and click NEXT
* On the LICENSE AGREEMENT screen you can specify a text file
containting a license that will be displayed to users. If you enable
this feature, users are prompted to accept alicense agreement by
clicking YES before the script will run
* On the PACKAGED FILES screen, click on ADD and then add the
myScript.bat and myScript.vbs files by navigating to the folder where
these files are stored. Once all files are added, click NEXT
* on the INSTALL PROGRAM TO LAUNCH screen select myScript.bat from the
INSTALL PROGRAM drop down list and click NEXT
* on the SHOW WINDOW screen leave 'Default' selected and click NEXT
* On the FINISHED MESSAGE screen you can enter a brief note to display
in a dialog box once the script completes. If not needed leave NO
MESSAGE selected and click NEXT
*On the PACKAGE NAME AND OPTIONS screen, click BROWSE and specify the
EXE file name that should be created, e.g. myScript.EXE. Under options
you can choose to hide the extraction window. I don't use the 'Store
File names ...' option but you could if needed. Click NEXT when done
* On the CONFIGURE RESTART screen you can define restart options for
the package . If no restart needed then select NO RESTART and click
NEXT
* You can save the package directive file on this last screen. Cick
NEXT to move on to the CREATE PACKAGE screen and click NEXT to create
the package (i.e. myScript.exe)

Package is then created and you can deploy the resulting EXE to your
users.

'<------- SAMPLE BATCH FILE TO RUN .VBS SCRIPT INSIDE IEXPRESS EXE -->

@ECHO OFF
CLS
cscript %0\..\myscript.vbs //NOLOGO

'<-- END SAMPLE BATCH FILE -->

Notes:
1. %0\..\ --> tell batch file to look for myScript.vbs in same
directory as the batch file
2. When a user runs the myScript.exe package the source files are
extracted to a folder under the users TEMP folder (i.e. C:\Documents
and Settings\%username%\Local Settings\Temp. The package install
command is run (i.e. myScript.bat) and when done this temp folder is
deleted.

Hope this helps.
 
J

JAQK

I'm afraid I've totally misstated the question.

Yes, I can run it from the command-line, but I really need to run it as a
regularly scheduled task.

Now I could do that with a batch file, but I don't know how to encapsulate
the command line syntax into a batch file.

Just taking

'(start) cscript myscript.vbs >file.txt'

and dumping into the batch file, will run the script, but won't write to the
file, which is what I really need. This works only when I run it manually
from the command line.
 
J

JAQK

cscript works when I run the script manually from the command line.

what's the advantage of wscript.exe ?
 
R

Richard Mueller

Hi,

One solution is to modify the VBScript to use the FileSystemObject to write
the output to a text file. In brief:

=======================
' Specify text file.
strFile = "c:\Scripts\report.txt"

' Open text file for write access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 2, True, 0)

' Write a line to the file.
objFile.WriteLine "User Name: " & strName

' Close the file.
objFile.Close
======================

Where you may have used MsgBox or Wscript.Echo commands, you replace with
objFile.WriteLine. The script can write to anywhere accessible, but you need
to give the scheduled task sufficient permissions to write to the file.
 
A

axtens

I can run it from the command-line, but I really need to run it as a regularly scheduled task

So perhaps you should look into leveraging the AT command

HELP AT gives:
..The AT command schedules commands and programs to run on a computer at
a specified time and date.

The Schedule service must be running to use the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE] [ /EVERY:date[,...] |
/NEXT:date[,...]] "command"
\\computername Specifies a remote computer.
Commands are scheduled on the local computer if this parameter is
omitted. id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further confirmation is
desired. time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week
or month. If date is omitted, the current day of the month is assumed.
/next:date[,...] Runs the specified command on the next occurrence of
the day (for example, next Thursday). If date is omitted, the current
day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top