Silently Install Software

Table of Contents

A common request in these threads is how to deploy software, so heres my take on it.
Allows you to download a file and run parameters to silently install it.
Once again, this will be more useful when GFI implements the ability to run a script once off.

As for what switches to Install the files you will need to find yourselves.
You can check out which has a lot of command switches for popular software.

Silently Install Software, Screwloose IT

'------------------------------------------------------------------------------ 
' silent_install.vbs 
'------------------------------------------------------------------------------ 
' Script that will download and install software. 
'------------------------------------------------------------------------------
'Usage: silent_install.vbs /URL: /Execute: /SaveTo: /Overwrite:[True/False]
' 
'   URL: File To download
'   Execute: Command to install
'   (Optional) SaveTo: Folder to download File
'   (Optional) Overwrite: Overwrite file if already Exists
' 
' ex: silent_install /URL:"http://fs10.filehippo.com/5277/b168ef4247da470195bae799a4a9df0d/ccsetup316.exe" /Execute:"ccsetup316.exe /S"
'
'------------------------------------------------------------------------------ 
' Author: Jake Paternoster
' Created: 21/03/2012 (Info@Screwloose.com.au)
'------------------------------------------------------------------------------ 

strURL = WScript.Arguments.Named("URL")
strExecute = WScript.Arguments.Named("Execute")
strSaveTo = WScript.Arguments.Named("SaveTo")
If LCase(WScript.Arguments.Named("Overwrite")) = "true" Then blnOverwrite = True

If strURL = "" Or strExecute = "" Then
 usage
End If

If strSaveTo = "" Then
 strSaveTo = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
End If

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists(strSaveTo) Then
 strFile = objFSO.BuildPath(strSaveTo, Mid(strURL, InStrRev(strURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists(Left(strSaveTo, InStrRev(strSaveTo, "\" ) - 1 ) ) Then
 strFile = strSaveTo
Else
 WScript.Echo "ERROR: Target folder not found."
 WScript.Quit(2)
End If

If blnOverwrite = "" Then
 blnOverwrite = False
End If

If objFSO.Fileexists(strFile) And blnOverwrite = False Then 
 WScript.Echo strFile & " Already Exists!"
 WScript.Echo "Exiting..."
 WScript.Quit(0)
ElseIf objFSO.Fileexists(strFile) And blnOverwrite = True Then
 WScript.Echo strFile & " Already Exists!"
 WScript.Echo "Forcing Overwrite..."
 objFSO.DeleteFile strFile
End If

WScript.Echo "Downloading " & strURL & " to " & strSaveTo
HTTPDownload strURL, strFile

Set oCmd = CreateObject("Wscript.Shell") 

commandLine = "%comspec% /c " & strSaveTo & "\" & strExecute 
WScript.Echo "Running " & commandLine
oCmd.Run commandLine, 0, True
WScript.Quit(0)

Sub usage 
 '------------------------------------------------------------------------------ 
 WScript.Echo "Usage: silent_install.vbs /URL: /Execute: /SaveTo: /Overwrite:[True/False]" 
 WScript.Echo " " 
 WScript.Echo "URL: File To download" 
 WScript.Echo "Execute: Command to install"
 WScript.Echo "(Optional) SaveTo: Folder to download File"
 WScript.Echo "(Optional) Overwrite: Overwrite file if already Exists"
 WScript.Echo " " 
 WScript.Echo " ex: silent_install /URL:""http://fs10.filehippo.com/5277/b168ef4247da470195bae799a4a9df0d/ccsetup316.exe"" /Execute:""ccsetup316.exe /S""" 
 WScript.Quit(1) 
End Sub 

Sub HTTPDownload(myURL, strFile)
 
 Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

 objXMLHTTP.open "GET", myURL, false
 objXMLHTTP.send()

 If objXMLHTTP.Status = 200 Then
 Set objADOStream = CreateObject("ADODB.Stream")
 objADOStream.Open
 objADOStream.Type = 1 'adTypeBinary

 objADOStream.Write objXMLHTTP.ResponseBody
 objADOStream.Position = 0 'Set the stream position to the start

 objADOStream.SaveToFile strFile
 objADOStream.Close
 Set objADOStream = Nothing
 End if

 Set objXMLHTTP = Nothing
End Sub

Our Services