param($machine) # Remote Projection using Titanium script v 2.0 2/18/15 by Bruce Cowper # This script launches the Titanium app on the local machine and provides a toggle on / off mechanism. i.e. if Titanium is not running, it it launched, if it is running, it is killed. # It also triggers the running of the Launch Titanium script on the remote machine via the use of the LAUNCHTT trigger in the Four Winds Interactive tool to set the remote $machine in to recieve mode # the $machine parameter allows for a setting a remote machine name. function Running ($app) { # This function tests to see if the $app is running and either returns the process ID, or $False $Running = Get-Process $app -ErrorAction SilentlyContinue if($Running -eq $null) { $Running = $False } return $Running } # set variable defaults IF ($machine -eq $null) # if no $machine paramater is passed, set a default. Edit as required. { $machine = "ebcdemo_yoga" } # note: code is not used n this instance, but just in case... setting this variable will pass a code to the remote Titanium machine $code = "" $args = $machine+" "+$code $appname = "TitaniumApp" # check to see what OS version is installed - note that the path for Titanium will change between the x86 and x64 bit OS versions. if ((Get-WmiObject -Class Win32_OperatingSystem -ea 0).OSArchitecture -eq '64-bit') { $apppath = "C:\Program Files (x86)\Microsoft Research\Titanium Projection\" } else { $apppath = "C:\Program Files\Microsoft Research\Titanium Projection\" } $fullapp = $apppath+$appname $running = $False # set CMS variables, Trigger URL and connection ID $URL = "http://"+$machine+":10561/player/readerId/LAUNCHTT" $username = "ebc" $password = "Cloud_33" $domain = "" # import window handler functions $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32 # Minimize Powershell $PSId = @(Get-Process "powershell" -ErrorAction SilentlyContinue)[0].MainWindowHandle [Win32.NativeMethods]::ShowWindowAsync($PSId, 2) # check to see if the $app is running $running = Running ($appname) If ($running -eq $False) #if the app is not running { # send command to remote CMS machine to launch Titanium $webclient = new-object System.Net.WebClient $webclient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain) $webpage = $webclient.DownloadString($URL) # start app - note make sure the working directory $apppath is set as Titanium will fail to authenticate $app = start-process $fullapp -ArgumentList $args -workingdirectory $apppath -passthru start-sleep 1 # minimize window If ($app.MainWindowHandle) { [Win32.NativeMethods]::ShowWindowAsync($app.MainWindowHandle, 6) } } Else { # If the process is already running, we want to kill it. This allows us to toggle the app state Get-Process $appname | Stop-Process # send command to remote CMS machine to kill Titanium - watch for getting the apps out of sync! The script for launching the Titanium projector will kill the process if it is already running (toggle on/off) $webclient = new-object System.Net.WebClient $webclient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain) $webpage = $webclient.DownloadString($URL) }