Tuesday, 18 May 2010

Start-Process.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script creates and starts a Process using .NET 
  4. .DESCRIPTION 
  5.     This script Creates a process object and sets 
  6.     the executable to notepad. The script then starts 
  7.     the process. 
  8. .NOTES 
  9.     File Name  : Start-Process.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/05/start-processps1.html
  15.     MSDN Sample posted at: 
  16.         http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx  
  17. .EXAMPLE 
  18.    When this script runs - you see a copy of notepad popup. 
  19. #> 
  20.  
  21. ## 
  22. # Start of Script 
  23. ## 
  24.  
  25. # Create a new process object 
  26. $Process = new-object System.Diagnostics.Process  
  27. try  { 
  28. $Process.StartInfo.UseShellExecute = $false 
  29.  
  30. # Pick process to start  now - for excitement, use notepad.exe 
  31. $Process.StartInfo.FileName = "C:\windows\system32\notepad.exe" 
  32.  
  33. # Start process  
  34. $Process.Start() 
  35. catch { 
  36.   " Error:";$Error[0]  

No comments: