【发布时间】:2014-05-22 14:44:06
【问题描述】:
Windows 7 注销后我不会调用我的 wpf 应用程序。我编写了一个调用我的 wpf 应用程序并等待 wpf 应用程序关闭的 powershell 脚本。 代码
$p = New-Object System.Diagnostics.Process
$pinfo = New-Object System.Diagnostics.ProcessStartInfo("D:\PowerShell\PsWpf.exe");
$p.StartInfo = $pinfo;
$p.Start();
$p.WaitForExit();
当我尝试将此脚本用作注销脚本时,在 Windows 设置-->脚本-->注销下的 gpedit.msc 中配置,然后我的计算机冻结,这意味着没有反应。
如果我像往常一样执行脚本,这意味着右键单击 powershell 文件,然后“使用 Powershell 运行”,一切运行正常。
Windows 注销后如何在 powershell 中调用我的 wpf 应用程序?
我知道可以在 powershell 中使用 wpf,比如
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase
[xml]$xaml =
@"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PowerShell WPF" Height="244" Width="525" FontFamily="Calibri" FontWeight="Bold" ResizeMode="NoResize">
<Grid Background="#58000000">
<Label Content="Designed and Developed by Free Lancer" Height="28" HorizontalAlignment="Left" Margin="288,165,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Window>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
$Window.ShowDialog() | Out-Null
并将其用作注销脚本,它可以正常工作。我的问题是,我不能仅在 .NET 中使用 powershell 编写脚本。
【问题讨论】:
标签: c# wpf windows powershell