VBScript iExpress Question

Joined
Dec 6, 2011
Messages
2
Reaction score
0
I have been bashing my head against this problem for a week and all I have to show for it is a sore head!

I am trying to use iExpress to create a self-extract package for "MyProg". It ought to be really really simple! I am using the install script below as the install script in iExpress. It works fine if I just run the script standalone but it fails with no messages when I run the self-extract exe

' ========= INSTALL THE MyProgram.EXE FILE ======================
Option Explicit
Const ALL_USERS = True

dim fso, tfolder
set fso=CreateObject("Scripting.FileSystemObject")
Const TemporaryFolder = 2
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)

' Set up the target folder
dim newfolder, newfolderpath
newfolderpath = "c:\Program Files\MyProgram"
If Not fso.FolderExists(newfolderpath) Then
Set newfolder = fso.CreateFolder(newfolderpath)
WScript.echo "A new folder has been created at: " & newfolderpath
Else
WScript.echo newfolderpath & " already exists"
End If

' Copy the file to the target folder
dim filespec, toloc
filespec=tfolder & "\MyProgram.exe" ' Where else would I find the newly unpacked file?
toloc="c:\Program Files\MyProgram\"
If fso.FileExists(filespec) Then
fso.CopyFile filespec, toloc, true
WScript.echo filespec & " copied to " & toloc
Else
WScript.echo "Unable to find " & filespec
End If
' ===================================================

Help! :cry: What am I doing wrong?
Garth
 
Joined
Dec 6, 2011
Messages
2
Reaction score
0
Aha - solved it! In case it is useful to anyone else here is my solution

' ========= INSTALL THE myprogram.EXE FILE ======================
Option Explicit
Const ALL_USERS = True

dim fso, logfile
set fso=CreateObject("Scripting.FileSystemObject")
Set logfile= fso.CreateTextFile("c:\myprogramlog.txt", True)
logfile.WriteLine("======== Installation of myprogram.exe started ==============")

' Set up the target folder
dim newfolder, newfolderpath
newfolderpath = "c:\Program Files\myprogram"
If Not fso.FolderExists(newfolderpath) Then
Set newfolder = fso.CreateFolder(newfolderpath)
logfile.WriteLine("A new folder has been created at: " & newfolderpath )
Else
logfile.WriteLine( newfolderpath & " already exists" )
End If

' Copy the file to the target folder
dim intemp, inwindows, toloc, tfolder, wfolder, file1, file2, file3, file4
toloc="c:\Program Files\myprogram\"
Const WindowsFolder=0, SystemFolder=1, TemporaryFolder = 2
'0 - WindowsFolder, containing the files installed by the operating system.
'1 - SystemFolder, containing fonts, libraries and device drivers required by the operating system.
'2 - TemporaryFolder, used to store temporary (.TMP) files.
file1="myprogram.exe"
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
file2 = tfolder & "\myprogram.exe"
Set wfolder = fso.GetSpecialFolder(WindowsFolder)
file3 = wfolder & "\myprogram.exe"
file4 = wfolder & "\Temp\myprogram.exe"

'logfile.WriteLine("1: " & file1)
'logfile.WriteLine("2: " & file2)
'logfile.WriteLine("3: " & file3)
'logfile.WriteLine("4: " & file4)

if fso.FileExists(file1) then
fso.CopyFile file1, toloc, true
logfile.WriteLine(file1 & " copied to " & toloc)
elseif fso.FileExists(file2) then
fso.CopyFile file2, toloc, true
logfile.WriteLine(file2 & " copied to " & toloc)
elseif fso.FileExists(file3) then
fso.CopyFile file3, toloc, true
logfile.WriteLine(file3 & " copied to " & toloc)
elseif fso.FileExists(file4) then
fso.CopyFile file4, toloc, true
logfile.WriteLine(file4 & " copied to " & toloc)
else
logfile.WriteLine("Unable to find myprogram.exe - installation failed")
end if

logfile.Close
WScript.Quit

Also, make sure you enter "cscript IntallScript" and "cscript AddShortcut.vbs" in the appropriate fields of iExpress to call the scripts. In case anyone is interested my second script sets up a shortcut and a hot key (Ctrl+Shift+S)

Option Explicit
Dim objShell, objDesktop, objLink, fso, logfile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set fso=CreateObject("Scripting.FileSystemObject")
Set logfile = fso.OpenTextFile("c:\myprogramlog.txt", ForAppending, True)

Dim strAppPath, strWorkDir, strIconPath
strWorkDir ="C:\Program Files\myprogram"
strAppPath = "C:\Program Files\myprogram\myprogram.exe"
'strIconPath = "%SystemRoot%\system32\SHELL32.dll,5"
strIconPath = "C:\Program Files\myprogram\myprogram.exe"
If fso.FileExists(strAppPath) Then

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Personal myprogram.lnk")

' Section which adds the shortcut's key properties

objLink.Description = "Personal myprogram"
objLink.HotKey = "CTRL+SHIFT+S"
objLink.IconLocation = strIconPath
objLink.TargetPath = strAppPath
objLink.WindowStyle = 2
objLink.WorkingDirectory = strWorkDir
objLink.Save
logfile.WriteLine("Shortcut and HotKey (CTRL+SHIFT+S) added")
Else
logfile.WriteLine("Unable to find '" & strAppPath & "'")
End if


logfile.WriteLine("========== Log Finished ==============")
logfile.Close
WScript.Quit
 

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