Silently Install Software
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
'------------------------------------------------------------------------------ ' silent_install.vbs '------------------------------------------------------------------------------ ' Script that will download and install software. '------------------------------------------------------------------------------ 'Usage: silent_install.vbs /URL:<FileURL> /Execute:<InstallCommand> /SaveTo:<OptionalOutputFolder> /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:<FileURL> /Execute:<InstallCommand> /SaveTo:<OptionalOutputFolder> /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 |