Jump to content

Install Winrar with PowerShell


kavaa

Recommended Posts

I made a install script for Winrar to do a Silent install.

UPDATED VERSION 2 With auto detect if Invoke-WebRequest exists

Improvements are welcome!

When a new version of Winrar comes out, just change the winrar-x64-540.exe to the new value.

# Silent Install Winrar
# http://www.winrar.com

# Path for the workdir
$workdir = "c:\installer\"

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer

$source = "http://rarlab.com/rar/winrar-x64-540.exe"
$destination = "$workdir\winrar.exe"
Invoke-WebRequest $source -OutFile $destination

# Start the installation

Start-Process -FilePath "$workdir\winrar.exe" -ArgumentList "/S"

# Wait XX Seconds for the installation to finish

Start-Sleep -s 35

# Remove the installer

rm -Force $workdir\w*

For Windows 7 please change 

$source = "http://rarlab.com/rar/winrar-x64-540.exe"
$destination = "$workdir\winrar.exe"
Invoke-WebRequest $source -OutFile $destination

To

$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("http://rarlab.com/rar/winrar-x64-540.exe","$workdir\winrar.exe")

Since Powershell in Windows 7 does not support the Invoke-WebRequest

Link to comment
Share on other sites

7 minutes ago, ComputerConsulting said:

I tried this script.

It did not install.

I opened the directory c:\installer and watched it while I ran the script a second time.

I never saw a file appear in this directory.

I tested this on Windows 7 

Since I only have Windows 8 and up Machines at the moment I cannot test it.

I'm going to install a Windows 7 VM now to test it on there as well.

p.s. the files gets downloaded via PowerShell and it could be slow.

Link to comment
Share on other sites

40 minutes ago, Paul said:

Thank you for your scripts. BTW: You can use -Wait on the Start-Process to wait for the process to exit. An alternative would be Wait-Process which also supports -Timeout. Great job.

-Paul

I did try it with that, but sometimes it failed. So that's why I went back to a old fashion Wait...

Link to comment
Share on other sites

3 minutes ago, ComputerConsulting said:

I watched the script finish in less than a minute.  

If you have a Fast Connection that's normal then ;) 

But if its not installed then something is Wrong.

I need to test it on Windows 7 only tested it on Windows 10

Link to comment
Share on other sites

2 minutes ago, ComputerConsulting said:

 


$destination = "$workdir\winrar.exe"

 

I know next to nothing about PowerShell scripting, but why did you end the line with winrar.exe ?  That's not a directory, that's a file.

$source = "http://rarlab.com/rar/winrar-x64-540.exe" -> Download Location
$destination = "$workdir\winrar.exe" -> Location where the file needs to be saved
Invoke-WebRequest $source -OutFile $destination -> Command that executes the download

So the download should be saved in the $workdir and the workdir = C:\installer 

That's where the Destination is for.

1 minute ago, ComputerConsulting said:

You have a 35 second sleep in the script.  

The script runs for 35 seconds.  

True, that is so that the script waits 35sec. before removing the Installer.

Link to comment
Share on other sites

Version 2

This version will check if the Invoke-WebRequest Command exists or not. For legacy Systems like Windows 7 you than only have one Script and don't need to change things in Pulseway

# Silent Install Winrar
# http://www.winrar.com

# Path for the workdir
$workdir = "c:\installer\"

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer

$source = "http://rarlab.com/rar/winrar-x64-540.exe"
$destination = "$workdir\winrar.exe"

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command 'Invoke-Webrequest')
{
     Invoke-WebRequest $source -OutFile $destination
}
else
{
    $WebClient = New-Object System.Net.WebClient
    $webclient.DownloadFile($source, $destination)
}

# Start the installation

Start-Process -FilePath "$workdir\winrar.exe" -ArgumentList "/S"

# Wait XX Seconds for the installation to finish

Start-Sleep -s 35

# Remove the installer

rm -Force $workdir\w*

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...