![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Demo: Writing a PS script app wrapper for Halo Just for kicks, I decided to take an arbitrary windows game that has commandline options and see how easily I could do a complete wrapper script for it. The target of choice was Halo/Halo CE, and the result is Invoke-Halo.ps1 - attached as a text file and also inserted below for the attachment-challenged. This doesn't do anything earth-shattering unless you've been dying to invoke Halo from a PowerShell prompt. It does, however, show that there is some value to using PowerShell for invoking traditional applications. For example, it uses registry settings to find either Halo or Halo C# (if you include the -CE switch) so the script is machine-independent - no customization is necessary if either application is in a custom location. Also, since it returns the process handle, it's possible to use this to monitor process properties. For people who run gaming servers, this could be used as part of a monitoring script that could forcibly restart the application if it crashes or if it begins to consume too many resources. # Invoke-Halo.ps1 # All parameters except for CE/StartInfo are PS-ified standard Halo params. # -CE: causes Halo CE to be launched instead of Halo. # -StartInfo: returns System.Diagnostics.ProcessStartInfo without # starting Halo. Param( [switch]$CE, [switch]$SoundOff, [switch]$VideoOff, [switch]$JoystickOff, [switch]$GammaOff, [int]$shaders = -1, [switch]$SafeMode, [switch]$Windowed, [switch]$Width640, [array]$VideoMode = @(), [int]$Adapter = 0, [int]$ServerPort = 0, [int]$ClientPort = 0, [string]$IpAddress = "", [switch]$Screenshot, [switch]$Timedemo, [switch]$Debug ) $HaloProcess = New-Object System.Diagnostics.ProcessStartInfo #$HaloProcess.LoadUserProfile = $true; # Let's be paranoid and assume hklm: has been un-mapped... $RegistryPath = "Registry::hklm\SOFTWARE\Microsoft\Microsoft Games\Halo"; $filename = "halo.exe"; if($CE){$RegistryPath = "$RegistryPath CE"; $filename = "haloce.exe";} $key = Get-Item -Path $RegistryPath $HaloProcess.WorkingDirectory = $key.GetValue("EXE Path"); # This can't be looked up in the registry. $HaloProcess.FileName = $filename; Remove-Variable key,filename,RegistryPath # Build arguments string $a = @(); if($SoundOff){$a += "-nosound"}; if($VideoOff){$a += "-novideo"}; if($JoystickOff){$a += "-nojoystick"}; if($GammaOff){$a += "-nogamma"}; if($Shaders) { switch($Shaders) { f{$a+="-useff"} 1.1{$a+="-use11"} 2{$a+="-use20"} } } if($SafeMode){$a += "-safemode"}; if($Windowed){$a += "-window"}; if($Width640){$a += "-width640"}; if($VideoMode) { $a += "-vidmode " + ("{0},{1},{2}" -f $VideoMode[0],$VideoMode[1],$VideoMode[2]) }; if($Adapter){$a += "-adapter $Adapter"}; if($ServerPort){$a += "-port $ServerPort"}; if($ClientPort ){$a += "-cport $ClientPort"}; if($IpAddress){$a += "-ip $IpAddress"}; if($Screenshot){$a += "-screenshot"}; if($WhatIf){$a += "-timedemo"}; if($Debug){$a += "-console"}; $ofs = " "; $HaloProcess.Arguments = "$a"; if($StartInfo) { $HaloProcess; } else { [System.Diagnostics.Process]::Start($HaloProcess); } |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Powershell Wrapper Script Problems - Trying to Call PowershellExchange 2007 Commands from Secondary Language (Like VBScript) | PowerShell | |||
| Start-Demo - a script to help you run demos | PowerShell | |||
| writing ps script | PowerShell | |||
| Demo Invoke-MsTsClient script | PowerShell | |||
| Demo Get-Rfc script | PowerShell | |||