pherb
pherb

Reputation: 33

Batch file / powershell: downloading and silent installing script

I am trying to write a script that will, ideally, download the .exe/.msi files for different programs, and run them silently. These installations do usually require input, like clicking next, or check a radio button. If I know what installation settings I want to run, how can I get these installations to run them in the way I want, but silently? Will the coding be simplier to do using batch programming or using Powershell? (I am a complete beginner to both, so no preference. Suggestions would be much appreciated). The script would ideally then be packaged up into it's own .exe file to run on any windows computer.

Upvotes: 2

Views: 13196

Answers (2)

Skatterbrainz
Skatterbrainz

Reputation: 1087

Another option is to use Chocolatey, but that depends on whether the required applications are already packaged (you can package your own as well, provided there are no licensing or redistribution limitations).

Upvotes: 0

Eric Eskildsen
Eric Eskildsen

Reputation: 4759

Downloading the Installers

This is the easy part. In PowerShell 3 or newer, you can download via Invoke-WebRequest:

Invoke-WebRequest 'http://example.com/installer.exe' -OutFile 'installer.exe'

In earlier versions, you can create a WebClient object and use its DownloadFile method:

$Client = New-Object System.Net.WebClient
$Client.DownloadFile('http://example.com/installer.exe', 'installer.exe')

If you had a text file listing all the installers you needed to download, one URL per line, you could download them all like so:

Get-Content 'installers.txt' | % { Invoke-WebRequest $_ -OutFile ($_ -replace '^.*?([^/]+$)', '$1') }

Running the Installers

This is the hard(er) part. Automating UIs is messy in general, and PowerShell doesn't go out of its way to support it. It can be done with the .NET Framework, but PowerShell is really better suited for manipulating data directly.

If you have to do UI automation, though, I'd recommend an alternative like AutoIt. AutoIt is a kind of mashup of VBScript, PowerShell, and a few other languages that makes it easy to do things like click buttons and enter text into text boxes automatically. It's commonly used to automate GUI installations.

Alternatively, consider repackaging the EXE installers as MSIs before deployment. MSIs are made for silent installs. Their property values can be self-contained (or stored in MST files) so that a user doesn't have to type them in at runtime, so there's no need to automate their UIs. Smart Package Community Edition (formerly WinInstall LE) is freeware that can scan the files and registry entries created by an installer and package them into an MSI file for you.

Hope this helps!

Upvotes: 8

Related Questions