Introduction
This utility can be used for rolling out utilities and patches to end users, or to package an application for use in Windows systems. This installer framework supports all environment vars used in Windows XP, so it should be easy to code with compatibility in mind.
Background
Basically, you just include the names and locations of the files to be copied, whether or not each file will be linked or registered; then, cut some custom processing code. Simple.
Using the code
Edit this script:
- Enter the locations of the source files.
- Enter the destination paths for each file.
- Decide if you want a link or hotkey created.
- Decide if you need to register the file.
- Enter any custom procedures that are necessary (if any).
- Run it!
Option Explicit
Dim sh, fso, dict
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
Dim strProgramName, strProgramMajorVersion, _
strProgramMinorVersion
Dim strProgramBuild, strProgramAuthor, _
strCreationDate, displayBuildNumber
strProgramName = "<program_name>"
strProgramMajorVersion = "v0"
strProgramMinorVersion = "1"
strProgramBuild = "1"
strProgramAuthor = "Brian Velde"
strCreationDate = "2007"
displayBuildNumber = False
Dim evallusersprofile, evappdata, evcd, evcmdcmdline,
evcomputername, evcomspec, evdate
Dim everrorlevel, evhomedrive, evhomepath, evhomeshare,
evlogonserver, evnumber_of_processors
Dim evos, evpath, evpathext, evprocessor_architecture,
evprogramfiles, evprompt, evrandom
Dim evsystemdrive, evsystemroot, evtemp, evtmp, evtime,
evuserdomain, evusername, evuserprofile, evwindir
evallusersprofile = sh.ExpandEnvironmentStrings("%allusersprofile%")
evappdata = sh.ExpandEnvironmentStrings("%appdata%")
evcd = sh.ExpandEnvironmentStrings("%cd%")
evcmdcmdline = sh.ExpandEnvironmentStrings("%cmdcmdline%")
evcomputername = sh.ExpandEnvironmentStrings("%computername%")
evcomspec = sh.ExpandEnvironmentStrings("%comspec%")
evdate = sh.ExpandEnvironmentStrings("%date%")
everrorlevel = sh.ExpandEnvironmentStrings("%errorlevel%")
evhomedrive = sh.ExpandEnvironmentStrings("%homedrive%")
evhomepath = sh.ExpandEnvironmentStrings("%homepath%")
evhomeshare = sh.ExpandEnvironmentStrings("%homeshare%")
evlogonserver = sh.ExpandEnvironmentStrings("%logonserver%")
evnumber_of_processors = _
sh.ExpandEnvironmentStrings("%number_of_processors%")
evos = sh.ExpandEnvironmentStrings("%os%")
evpath = sh.ExpandEnvironmentStrings("%path%")
evpathext = sh.ExpandEnvironmentStrings("%pathext%")
evprocessor_architecture = _
sh.ExpandEnvironmentStrings("%processor_architecture%")
evprogramfiles = sh.ExpandEnvironmentStrings("%programfiles%")
evprompt = sh.ExpandEnvironmentStrings("%prompt%")
evrandom = sh.ExpandEnvironmentStrings("%random%")
evsystemdrive = sh.ExpandEnvironmentStrings("%systemdrive%")
evsystemroot = sh.ExpandEnvironmentStrings("%systemroot%")
evtemp = sh.ExpandEnvironmentStrings("%temp%")
evtmp = sh.ExpandEnvironmentStrings("%tmp%")
evtime = sh.ExpandEnvironmentStrings("%time%")
evuserdomain = sh.ExpandEnvironmentStrings("%userdomain%")
evusername = sh.ExpandEnvironmentStrings("%username%")
evuserprofile = sh.ExpandEnvironmentStrings("%userprofile%")
evwindir = sh.ExpandEnvironmentStrings("%windir%")
Dim installPath
Dim extraFolders(2)
installPath = ""
extraFolders(0) = ""
extraFolders(1) = ""
Dim fileSrc(10)
Dim fileDst(10)
Dim linkTarget(10)
Dim linkLocation(10)
Dim regFile(10)
Dim hotKey(10)
fileSrc(0) = ""
fileDst(0) = ""
linkTarget(0) = fileDst(0)
linkLocation(0) = ""
regFile(0) = False
hotKey(0) = ""
fileSrc(1) = ""
fileDst(1) = ""
linkTarget(1) = fileDst(1)
linkLocation(1) = ""
regFile(1) = False
hotKey(1) = ""
fileSrc(2) = ""
fileDst(2) = ""
linkTarget(2) = fileDst(2)
linkLocation(2) = ""
regFile(2) = False
hotKey(2) = ""
fileSrc(3) = ""
fileDst(3) = ""
linkTarget(3) = fileDst(3)
linkLocation(3) = ""
regFile(3) = False
hotKey(3) = ""
fileSrc(4) = ""
fileDst(4) = ""
linkTarget(4) = fileDst(4)
linkLocation(4) = ""
regFile(4) = False
hotKey(4) = ""
fileSrc(5) = ""
fileDst(5) = ""
linkTarget(5) = fileDst(5)
linkLocation(5) = ""
regFile(5) = False
hotKey(5) = ""
fileSrc(6) = ""
fileDst(6) = ""
linkTarget(6) = fileDst(6)
linkLocation(6) = ""
regFile(6) = False
hotKey(6) = ""
fileSrc(7) = ""
fileDst(7) = ""
linkTarget(7) = fileDst(7)
linkLocation(7) = ""
regFile(7) = False
hotKey(7) = ""
fileSrc(8) = ""
fileDst(8) = ""
linkTarget(8) = fileDst(8)
linkLocation(8) = ""
regFile(8) = False
hotKey(8) = ""
fileSrc(9) = ""
fileDst(9) = ""
linkTarget(9) = fileDst(9)
linkLocation(9) = ""
regFile(9) = False
hotKey(9) = ""
Dim win98, win2k, winXP, win2k3, winVista
Function getOsVer()
Dim SystemSet, system, osVer
Set SystemSet = _
GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
For each System in SystemSet
osVer = System.Caption
If InStr(osVer, "Vista") Then
winVista = True
Else
winVista = False
End If
If InStr(osVer, "2003") Then
win2k3 = False
Else
win2k3 = True
End If
If InStr(osVer, "XP") Then
winXP = True
Else
winXP = False
End If
If InStr(osVer, "2000") Then
win2k = True
Else
win2k = False
End If
If InStr(osVer, "98") Then
win98 = True
Else
win98 = False
End If
Next
End Function
Function createDirs()
Dim max, i
If Not fso.FolderExists(installPath) AND installPath <> "" Then
fso.CreateFolder(installPath)
End If
i=0
max = UBound(extraFolders)
While (i < max)
If Not fso.FolderExists(extraFolders(i)) And extraFolders(i) <> "" Then
fso.CreateFolder(extraFolders(i))
End If
i = i+1
Wend
End Function
Function copyFiles()
Dim i, max
i = 0
max = UBound(fileSrc)
While (i < max)
If (fileSrc(i) <> "") Then
fso.CopyFile fileSrc(i), fileDst(i), True
End If
i = i+1
Wend
End Function
Function createShortcuts()
Dim outputLink, oLink, i, max
i = 0
max = UBound(linkTarget)
While (i < max)
If (linkLocation(i) <> "") Then
outputLink = linkLocation(i)
Set oLink = sh.CreateShortcut(outputLink)
oLink.TargetPath = linkTarget(i)
If hotKey(i) <> "" Then
oLink.HotKey = hotKey(i)
End If
oLink.IconLocation = linkTarget(i)
oLink.Save
Set oLink = Nothing
End If
i = i+1
Wend
End Function
Function registerFiles()
Dim result, i, command
i=0
While (i < UBound(fileDst))
If regFile(i) <> False Then
command = """" & evsystemroot & _
"\system32\regsvr32.exe""" & _
" """ & fileDst(i) & """"
sh.Exec command
End If
i = i+1
Wend
End Function
Function cleanup()
Set sh = Nothing
Set fso = Nothing
Set dict = Nothing
End Function
Dim installMsg, endMsg
If displayBuildNumber = True Then
installMsg = MsgBox("Do you wish to install " & strProgramName &_
" " & strProgramMajorVersion & _
"." & strProgramMinorVersion & _
" build " & strProgramBuild & _
"?",vbYesNo,"Install " _
& strProgramName & "?")
Else
installMsg = MsgBox("Do you wish to install " & _
strProgramName & " " & _
strProgramMajorVersion & "." & strProgramMinorVersion & _
"?",vbYesNo,"Install " & strProgramName & "?")
End If
If installMsg = vbNo Then
WScript.Quit(666)
End If
Call getOsVer()
Call createDirs()
Call copyFiles()
Call createShortcuts()
Call registerFiles()
Call cleanup()
endMsg = MsgBox("Installation of " & strProgramName & _
" " & strProgramMajorVersion & "." & _
strProgramMinorVersion & _
" has completed successfully!", vbOKOnly, "Finished!")
WScript.Quit(0)
Points of interest
This script saves me a lot of time... Nuf said...
History
- Version 1.1 - Uploaded 5-24-2007.