Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#needed for Set-ForegroundWindow
Write-Host "Installing PowerShell community modules..." -ForegroundColor Cyan
Install-Module -Name Pscx
Write-Host "Installing Kinect for Windows SDK 2.0..." -ForegroundColor Cyan
Write-Host "Downloading..."
$exePath = "$env:TEMP\KinectSDK-v2.0_1409-Setup.exe"
(New-Object Net.WebClient).DownloadFile('https://download.microsoft.com/download/F/2/D/F2D1012E-3BC6-49C5-B8B3-5ACFF58AF7B8/KinectSDK-v2.0_1409-Setup.exe', $exePath)
Write-Host "Installing..."
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
Start-process $exePath
# it starts 2 processes, one is interactive, we need second
while ((Get-Process | ? {$_.name -eq "KinectSDK-v2.0_1409-Setup"}).Count -ne 2) {sleep 1}
# with less timeout it is unstable
sleep 40
# select interactive process (uses more memory) and set it's window active
$procs = Get-Process -Name KinectSDK-v2.0_1409-Setup
if ($procs[0].VM -gt $procs[1].VM) {$id = $procs[0].Id} else {$id = $procs[1].Id}
for ($i=0; $i -le 10; $i++) { Set-ForegroundWindow (Get-Process -id $id).MainWindowHandle; sleep 1}
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait(" "); sleep 1
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); sleep 1
[System.Windows.Forms.SendKeys]::SendWait(" ")
$installed = $false
Write-Host "Waiting SDK to be installed..."
$count = 0
while(!$installed -and $count -lt 90) {
$installed = (Get-Service | ? {$_.name -eq "KinectMonitor"}).Count -gt 0
if(!$installed) {Write-Host -NoNewline "."; sleep 1; $count++}
}
if(!$installed) {throw "Kinect for Windows SDK 2.0 was not installed"} else {Write-Host " OK" -ForegroundColor Green}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment