Posted February 13, 20178 yr 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
February 13, 20178 yr Administrators 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
February 13, 20178 yr 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Â
February 13, 20178 yr Author 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.
February 13, 20178 yr Author 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...
February 13, 20178 yr  $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.
February 13, 20178 yr Author 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
February 13, 20178 yr Author 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.
February 14, 20178 yr Author 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* Â
Create an account or sign in to comment