Skip to content

Instantly share code, notes, and snippets.

@hl2guide
Last active June 13, 2016 07:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hl2guide/a8d81ddc3ec13092dfb4 to your computer and use it in GitHub Desktop.
Save hl2guide/a8d81ddc3ec13092dfb4 to your computer and use it in GitHub Desktop.
This script automates the installation and updating of MadVR (http://madvr.com). Script Version: 1.0e, Date Last Updated: 13th of June, 2016
# This script automates the installation and updating of MadVR (http://madvr.com).
# All checks and downloads are done with the official website.
# Version: 1.0e
# Date Last Updated: 13th of June, 2016
# Author: Deanoman
# Requirements: Windows 7 or later, NET Framework 4.5 or later, available internet connection
# Variables
# A) Set this to the folder MADVR is installed in (the only thing you need to set)
# This folder must exist, have enough space on the drive
# and the string must end in a \
# A1) Default MadVR folder: C:\Program Files (x86)\MadVR\
$madvrFolder = 'C:\Program Files (x86)\MadVR\'
# A2) Default K-Lite Codecs MadVR folder: C:\Program Files (x86)\K-Lite Codec Pack\Filters\madVR\
#$madvrFolder = 'C:\Program Files (x86)\K-Lite Codec Pack\Filters\madVR\'
$useBITSTransfer = 0
# ============ DO NOT EDIT BELOW ============
$scriptVersion = '1.0e'
$madVRChangeLog = $madvrFolder + 'changelog.txt'
$eventLogSourceName = 'MadVR Updater Script '+$scriptVersion
$eventLogInfoID = 1
$eventLogWarningID = 2
$eventLogErrorID = 3
New-EventLog –LogName Application –Source $eventLogSourceName -ErrorAction Ignore
# 0) Get Latest Version Number
$urlVersionCheck = 'http://madshi.net/madVR/version.txt'
$webclient = new-object System.Net.WebClient
$latestversion = $webclient.DownloadString($urlVersionCheck).Trim()
if(-Not($latestversion))
{
Write-Host
$message = "Failed to get latest version number from the internet.`nPlease check connection."
Write-Warning $message
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Warning –EventID $eventLogWarningID –Message $message
Break
}
# Get Installed version of MadVR from changelog.txt file
$installedVersionMadVR = (Get-Content -Path $madVRChangeLog -First 1 -ErrorAction Ignore)
if($installedVersionMadVR -eq($null)){$installedVersionMadVR = 'none'}
$installedVersionMadVR = $installedVersionMadVR.trimstart('v')
$installedVersionMadVR = $installedVersionMadVR.trimend(':')
$installedVersionMadVR = $installedVersionMadVR+'.0'
#0-1) Compare installed version to latest version
if($installedVersionMadVR -eq($latestversion))
{
Write-Host
$message = "MadVR is already up-to-date, version $latestversion. Well done :D"
Write-Host $message -ForegroundColor Green
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
Break
}
# 0-2) Get Version of BITS
$versionOfBITS = Get-Item 'C:\Windows\System32\qmgr.dll'
$versionOfBITS = Select-Object -InputObject $versionOfBITS -ExpandProperty VersionInfo
$versionOfBITS = Select-Object -InputObject $versionOfBITS -ExpandProperty ProductVersion
# Write-Host $versionOfBITS -ForegroundColor Green
# 1) Check is Administrator
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] 'Administrator'))
{
Write-Host
$message = "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Write-Warning $message
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Warning –EventID $eventLogWarningID –Message $message
Break
}
# 2) Check that MadVR is not running (madHcCtrl.exe)
$madvrProcess = [bool](Get-Process 'madHcCtrl' -ErrorAction 0)
if(-Not($madvrProcess -eq 0))
{
Write-Host
$message = "MadVR is running (madHcCtrl.exe).`nPlease re-run this script after closing MadVR."
Write-Warning $message
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Warning –EventID $eventLogWarningID –Message $message
Break
}
Write-Host
Write-Host 'MadVR' $latestversion' is available :D Yay!' -ForegroundColor Green
Write-Host 'Release Notes: http://forum.doom9.org/showthread.php?t=146228' -ForegroundColor Magenta
if($installedVersionMadVR -ne('none.0'))
{
Write-Host 'MadVR can be upgraded from: '$installedVersionMadVR' to '$latestversion -ForegroundColor Yellow
}
Write-Host 'If you continue, it will be downloaded and then installed to:' $madvrFolder -ForegroundColor Cyan
Write-Host
Pause
# 3) Download MadVR if it does not exist in script folder
$fileexists = Test-Path "$PSScriptRoot\madVR.zip"
if(-Not $fileexists)
{
# Source Code: https://blog.jourdant.me/3-ways-to-download-files-with-powershell
$url = 'http://madshi.net/madVR.zip'
$output = "$PSScriptRoot\madVR.zip"
$start_time = Get-Date
Write-Host
$message = "Downloading the latest MadVR ($latestversion) as 'madVR.zip', please wait..."
Write-Host $message -ForegroundColor Cyan
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
# Download using BITS if it is available
if($versionOfBITS -And($useBITSTransfer -eq(1)))
{
# Download using BITS, possibly faster method
Import-Module BitsTransfer
Start-BitsTransfer -Source $url -Destination $output
}
else
{
# Downlod using default, possibly slower method
Invoke-WebRequest -Uri $url -OutFile $output
}
Write-Host
$message = 'madVR.zip has been downloaded.'
Write-Host $message -ForegroundColor Green
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
Write-Host "Time taken: $((Get-Date).Subtract($start_time).Seconds+60) second(s)" -ForegroundColor Cyan
}
# 4) Check that MadVR is not running (madHcCtrl.exe)
$madvrProcess = [bool](Get-Process 'madHcCtrl' -ErrorAction 0)
if(-Not($madvrProcess -eq 0))
{
Write-Host
$message = "MadVR is running (madHcCtrl.exe).`nPlease re-run this script after closing MadVR."
Write-Warning $message
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Warning –EventID $eventLogWarningID –Message $message
Break
}
# 5) Unzip MadVR downloaded zip file
if((Get-Item "$PSScriptRoot\madVR.zip").length -gt 10278835)
{
Write-Host
$message = "Unzipping madVR.zip..."
Write-Host $message -ForegroundColor Cyan
$BackUpPath = "$PSScriptRoot\madVR.zip"
$Destination = "$PSScriptRoot\extracted-madvr\"
Add-Type -assembly 'system.io.compression.filesystem'
[io.compression.zipfile]::ExtractToDirectory($BackUpPath, $destination)
$extractedMadVR = $Destination
}
else
{
Write-Host
$message = "The downloaded file madVR.zip file seems to be invalid`nPlease check madVR.zip."
Write-Warning $message
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Warning –EventID $eventLogWarningID –Message $message
Break
}
# Create destination folder if it does exist (new installation)
$fileexists = Test-Path $madvrFolder
if(-Not $fileexists)
{
New-Item $madvrFolder -type directory -WarningAction Ignore -InformationAction Ignore
}
# 6) Move unzipped files to destination folder
Write-Host
$message = "Updating Existing Installation of MadVR."
Write-Host $message -ForegroundColor Magenta
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
Move-Item $extractedMadVR'\*.*' $madvrFolder -Force
Move-Item $extractedMadVR'\developers\' $madvrFolder -Force
Move-Item $extractedMadVR'\legal stuff\' $madvrFolder -Force
# 7) Remove MadVR Temporary Install Files
if(Test-Path "$PSScriptRoot\madVR.zip")
{
Remove-Item "$PSScriptRoot\madVR.zip"
}
if(Test-Path "$PSScriptRoot\extracted-madvr\")
{
Remove-Item "$PSScriptRoot\extracted-madvr\"
}
Write-Host
$message = 'MadVR has been updated to the latest version: '+$latestversion+', enjoy! :D'
Write-Host $message -ForegroundColor Green
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
$message = 'Installed to: '+$madvrFolder
Write-Host $message -ForegroundColor Green
Write-EventLog –LogName Application –Source $eventLogSourceName –EntryType Information –EventID $eventLogInfoID –Message $message
# 8) Prompt for running of install.bat - upcoming version.
<#$message = "Would you like to run MADVR's offical install.bat file?"+
"`nIt configures MADVR to be integrated into video players."+
"[This should only need to be done initially or after new video player is installed]"
$confirmation = Read-Host $message
while($confirmation -ne 'y' -or($confirmation -ne 'yes'))
{
Write-Host '...'
if ($confirmation -eq 'n' -or($confirmation -ne 'no')) {exit}
$confirmation = Read-Host $message
Process-Start $madvrFolder+'\install.bat' -
}#>
Exit
@hl2guide
Copy link
Author

This useful PowerShell script updates the version of MadVR to the latest official version available. It requires: Windows 7 or later, NET Framework 4.5 or later, an available and working internet connection. PowerShell ISE (GUI to run script) is installed by default on Windows 7 or later.

PowerShell System Requirements: https://technet.microsoft.com/en-au/library/hh847769.aspx

@hl2guide
Copy link
Author

Updated to version 1.0d.

@hl2guide
Copy link
Author

Version 1.0e is out and brings with it support for optional K-Lite Codecs MadVR folder (see A1 and A2 sections) [lines 14 and 16]

@hl2guide
Copy link
Author

The next version I'll release (1.1) will add many more features 👍 🎱 👯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment