Skip to content

Instantly share code, notes, and snippets.

@dancing-groot
Created May 31, 2024 09:59
Show Gist options
  • Save dancing-groot/3d6acc6a8d57151f27095c27c15ba932 to your computer and use it in GitHub Desktop.
Save dancing-groot/3d6acc6a8d57151f27095c27c15ba932 to your computer and use it in GitHub Desktop.
Cloudpaging Player - PSADT extract
If ($deploymentType -ine 'Uninstall')
{
##*===============================================
##* PRE-INSTALLATION
##*===============================================
[String]$installPhase = 'Pre-Installation'
## <Perform Pre-Installation tasks here>
If (Test-Path -LiteralPath "C:\Program Files\Numecent\Application Jukebox Player\JukeboxPlayer.exe")
{
# Upgrade
Show-InstallationWelcome -CloseApps 'JukeboxPlayer' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt
Show-InstallationProgress
Try
{
$currentCacheSize = [int]((Get-CloudpagingCache).Size)
}
Catch
{
$currentCacheSize = 0
}
Stop-Service -Name "StreamingCore" -ErrorAction SilentlyContinue
}
Else
{
# New Install
$currentCacheSize = 0
}
# Delete reference to the previous version's MSI file name, in case it is different (causes MSI error 1316)
Remove-ItemProperty -Path HKLM:\SOFTWARE\Classes\Installer\Products\C7BF6F322E1CB194191A40145D91B17C\SourceList -Name PackageName -ErrorAction SilentlyContinue
## Identify the size of the cache required
$cacheSize = "32768"
$studentCacheSize = "49152"
$registryCacheSize = [int](Get-ItemProperty -Path 'HKLM:\SOFTWARE\_CHANGEME_' -Name 'CloudpagingCacheSize' -ErrorAction SilentlyContinue).CloudpagingCacheSize
If ($registryCacheSize -eq 0)
{ Write-Log "No registry cache entry found" -Source "Cloudpaging Cache" }
Else
{ Write-Log "Registry cache entry found: $registryCacheSize MB" -Source "Cloudpaging Cache" }
If ($registryCacheSize -gt 0)
{
$cacheSize = $registryCacheSize
Write-Log -Message "Setting cache size to $cacheSize MB from registry" -Source "Cloudpaging Cache"
}
ElseIf ((Get-ItemProperty -Path 'HKLM:\SOFTWARE\_CHANGEME_' -Name 'DeviceType' -ErrorAction SilentlyContinue).DeviceType -eq "Student")
{
$cacheSize = $studentCacheSize
Write-Log -Message "Setting cache size to $cacheSize MB for a Student Desktop" -Source "Cloudpaging Cache"
}
Else
{
Write-Log -Message "Setting cache size to $cacheSize MB from default" -Source "Cloudpaging Cache"
}
##*===============================================
##* INSTALLATION
##*===============================================
[String]$installPhase = 'Installation'
## <Perform Installation tasks here>
If (Test-Path -LiteralPath "C:\Program Files\Numecent\Application Jukebox Player\JukeboxPlayer.exe")
{
# Upgrade
Write-Log -Message "Cloudpaging Player will be upgraded" -Source "Cloudpaging Player"
Execute-MSI -Action Install -SkipMSIAlreadyInstalledCheck -Path 'cloudpaging-player-setup-x64.msi' -Parameters "/qn /norestart REBOOT=ReallySuppress REINSTALL=ALL REINSTALLMODE=vamus"
### Resize cache at next boot if required by creating a scheduled task which will delete itself afterwards
If ($currentCacheSize -ne $cacheSize)
{
Write-Log -Message "Cache size will change from $currentCacheSize MB to $cacheSize MB" -Source "Cloudpaging Cache"
# Create the Scheduled Task action
$scheduleName = "Set Cloudpaging Cache"
$scheduleAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-Command `"Set-CloudpagingCache -Size $cacheSize;Unregister-ScheduledTask -TaskName '$scheduleName' -Confirm:`$false`""
# Set Scheduled Task to run as local SYSTEM account
$schedulePrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
# Set Scheduled Task to run at startup
$scheduleTrigger = New-ScheduledTaskTrigger -AtStartup
# Register the Scheduled Task - it will show up in default folder of Task Scheduler
Register-ScheduledTask -Action $scheduleAction -TaskName $scheduleName -TaskPath '\' -Principal $schedulePrincipal -Trigger $scheduleTrigger
}
Else
{
Write-Log -Message "Cache size does not need to change ($cacheSize MB)" -Source "Cloudpaging Cache"
}
}
Else
{
# New Install
Write-Log -Message "New installation of Cloudpaging Player" -Source "Cloudpaging Player"
Execute-MSI -Action Install -SkipMSIAlreadyInstalledCheck -Path 'cloudpaging-player-setup-x64.msi' -Parameters "/qn /norestart REBOOT=ReallySuppress ET_AUTO_ELEVATION=1 ET_CACHE_SIZE=`"$cacheSize`""
}
##*===============================================
##* POST-INSTALLATION
##*===============================================
[String]$installPhase = 'Post-Installation'
## <Perform Post-Installation tasks here>
Remove-File -Path 'C:\Users\Public\Desktop\Cloudpaging Player.lnk'
# Set HKLM registry keys
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Endeavors Technologies\StreamingCore\Settings' -Name 'AppFlags' -Value 0x20000000 -Type DWord
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Endeavors Technologies\StreamingCore\Settings' -Name 'DisableLocalPaging' -Value 1 -Type DWord
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Endeavors Technologies\StreamingCore\Settings\AppEvent' -Name 'AllowLocalSystem' -Value 1 -Type DWord
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Endeavors Technologies\StreamingCore\Settings\Cache' -Name 'CacheAutoGrow' -Value 0 -Type DWord
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Endeavors Technologies\StreamingCore\Settings\Driver' -Name 'PhysicalLayerMode' -Value 1 -Type DWord
# Set HKCU registry keys
[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key "HKCU\Software\Endeavors Technologies\Application Jukebox Player\Settings" -SID $UserProfile.SID
Set-RegistryKey -Key "HKCU\Software\Endeavors Technologies\Application Jukebox Player\Settings" -SID $UserProfile.SID -Name "ShowUIOnStartup" -Value 0 -Type Dword
Set-RegistryKey -Key "HKCU\Software\Endeavors Technologies\Application Jukebox Player\Settings" -SID $UserProfile.SID -Name "ShowClientStillRunReminder" -Value 0 -Type DWord
Set-RegistryKey -Key "HKCU\Software\Endeavors Technologies\Application Jukebox Player\Settings" -SID $UserProfile.SID -Name "BringToFront" -Value 1 -Type DWord
}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings
## Display a message at the end of the install
If ($DeployMode -eq 'Interactive')
{
Write-Log "Prompting for reboot"
Show-InstallationRestartPrompt -CountdownSeconds 3600 -CountdownNoHideSeconds 120
}
Else
{
if (((Get-LoggedOnUser -ErrorAction SilentlyContinue | Where-Object Username -eq 'defaultuser0').count) -eq 1)
{
# Autopilot OOBE - Schedule a reboot at the next startup
Write-Log "In Autopilot OOBE, will schedule a reboot later"
$scheduleName = "Reboot to finalise Cloudpaging Player installation"
$scheduleAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-Command `"Start-Process -FilePath 'C:\WINDOWS\system32\shutdown.exe' -ArgumentList '-r -t 0';Unregister-ScheduledTask -TaskName '$scheduleName' -Confirm:`$false`""
# Set Scheduled Task to run as local SYSTEM account
$schedulePrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
# Set Scheduled Task to run at startup
$scheduleTrigger = New-ScheduledTaskTrigger -AtStartup
# Register the Scheduled Task - it will show up in default folder of Task Scheduler
Register-ScheduledTask -Action $scheduleAction -TaskName $scheduleName -TaskPath '\' -Principal $schedulePrincipal -Trigger $scheduleTrigger
}
else
{
# Likely no user logged on
Write-Log "Automatic reboot scheduled"
Execute-Process -Path "C:\WINDOWS\system32\shutdown.exe" -Parameters "-r -t 20" -WindowStyle "Hidden" -NoWait
}
}
}
ElseIf ($deploymentType -ieq 'Uninstall')
{
##*===============================================
##* PRE-UNINSTALLATION
##*===============================================
[String]$installPhase = 'Pre-Uninstallation'
## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
#Show-InstallationWelcome -CloseApps 'iexplore' -CloseAppsCountdown 60
Show-InstallationWelcome -CloseApps 'JukeboxPlayer' -Silent
## Show Progress Message (with the default message)
Show-InstallationProgress
## <Perform Pre-Uninstallation tasks here>
Stop-ServiceAndDependencies -Name "StreamingCore"
##*===============================================
##* UNINSTALLATION
##*===============================================
[String]$installPhase = 'Uninstallation'
## <Perform Uninstallation tasks here>
Remove-MSIApplications -Name 'Cloudpaging Player'
##*===============================================
##* POST-UNINSTALLATION
##*===============================================
[String]$installPhase = 'Post-Uninstallation'
## <Perform Post-Uninstallation tasks here>
If ($DeployMode -eq 'Interactive')
{
Show-InstallationRestartPrompt -CountdownSeconds 3600 -CountdownNoHideSeconds 120
}
Else
{
Execute-Process -Path "C:\WINDOWS\system32\shutdown.exe" -Parameters "-r -t 20" -WindowStyle "Hidden" -NoWait
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment