在powershell中运行wpf程序的一种方法,修正

在run.sp1中
# Create a runspace to run Hello World
$rs = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
$rs.ApartmentState, $rs.ThreadOptions = “STA”, “ReuseThread”
$rs.Open()
$sb = [System.Management.Automation.ScriptBlock]::Create((Join-Path $pwd "hell0.ps1"))
$psCmd = $sb.GetPowerShell()
$psCmd.Runspace = $rs
$null = $psCmd.BeginInvoke()

在hell0.ps1中
# Reference the WPF assemblies
Add-Type –assemblyName PresentationFramework
Add-Type –assemblyName PresentationCore
Add-Type –assemblyName WindowsBase
$window = New-Object Windows.Window
$window.Title = $window.Content = “Hello World.  Check out PowerShell and WPF Together.”
$window.SizeToContent = “WidthAndHeight”
$null = $window.ShowDialog()


posted @ 2010-04-19 20:37  doujiu  阅读(374)  评论(0编辑  收藏  举报