If you find this project useful, please give it a star! Your support is appreciated and helps keep the project growing. 🌟
This PowerShell script automates the process of downloading, installing, and adding WinRAR to the system PATH on Windows machines 🪟.
Click the link to read Instructions 📄.
- Automated Download: Downloads the WinRAR installer directly from the official website 🌐.
- Silent Installation: Installs WinRAR silently without requiring user interaction 🛠️.
- PATH Update: Adds the WinRAR installation directory to the system PATH, allowing WinRAR commands to be run from anywhere in the command line ✅.
This script includes robust logging mechanisms to ensure detailed tracking of the script's operations and for troubleshooting 🔍.
- The script logs all actions and errors to a file named
winrar-install.log
located in the temporary directory.
The log file is saved in the user's temporary directory. The typical path is:
C:\Users<YourUsername>\AppData\Local\Temp\winrar-install.log
The script includes a custom function Log-Message
to handle logging. This function logs messages with a timestamp and a message type (INFO, ERROR, or WARNING).
function Log-Message {
param (
[string]$message,
[string]$type = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp [$type] $message"
Write-Host $logEntry
Add-Content -Path $logFile -Value $logEntry
}
- message: The message to log.
- type: The type of message (INFO, ERROR, WARNING). Default is "INFO".
- Info Message:
2024-07-18 14:32:01 [INFO] Starting download of WinRAR from https://www.win-rar.com/fileadmin/winrar-versions/winrar-x64-701.exe
- **Error Message:
2024-07-18 14:32:45 [ERROR] Failed to download WinRAR installer: Exception calling "Invoke-WebRequest" with "2" argument(s): "The remote server returned an error: (404) Not Found."
- Warning Message:
2024-07-18 14:33:10 [WARNING] Failed to remove the downloaded installer: Exception calling "Remove-Item" with "1" argument(s): "Cannot find path 'C:\Users\User\AppData\Local\Temp\winrar-installer.exe' because it does not exist."
- Starting Download: Logs the beginning of the download process.
Log-Message "Starting download of WinRAR from $url"
- Download Complete: Logs the completion of the download.
Log-Message "Download complete."
- Download Failure: Logs any errors during the download process.
Log-Message "Failed to download WinRAR installer: $_" "ERROR"
- Starting Installation: Logs the beginning of the installation process.
Log-Message "Starting silent installation of WinRAR."
- Installation Complete: Logs the completion of the installation.
Log-Message "WinRAR installation complete."
- Clean Up: Logs the removal of the downloaded installer.
Log-Message "Cleaned up the downloaded installer."
- PowerShell 5.0 or higher 🖥️.
- Internet connection to download the installer 🌐.
- Administrative privileges to install and update the system PATH 🔒.
Select the version that matches your system specs:
- For Windows 64-bit systems: Download 64-Bit Installer
- For Windows 32-bit systems: Download 32-Bit Installer
-
Open PowerShell (Run as Admin) 🔒.
-
Navigate to the directory containing the script using
cd
. -
Run the script:
.\WinRAR-7.01-auto-installer.ps1
-
The script will handle the rest, providing output messages to indicate progress and completion status.
If the script doesn't run, change the execution policy by running:
Set-ExecutionPolicy Bypass -Scope Process
- if a message pops up
red
typeY
click enter.
Then, run the script again without closing PowerShell.
.\WinRAR-7.01-auto-installer.ps1
- Download: The script starts by downloading the WinRAR installer using
Invoke-WebRequest
. - Install: After downloading, it proceeds to install WinRAR silently using the
/S
switch. - PATH Update: Finally, it checks if WinRAR's installation path is in the system PATH. If not, it adds it, allowing WinRAR commands to be run from the command line.
This script is for educational purposes and should be used responsibly. Ensure you have the right to install software on your machine
This script is provided "as is", without warranty of any kind, express or implied. Use it at your own risk.