【发布时间】:2020-12-20 09:25:17
【问题描述】:
我创建了一个用于安装 adobe 的 powershell 脚本。现在我想创建一个 GUI 来使用它并指定 adobe 安装文件的路径。该安装文件位置应作为脚本的输入,然后运行整个脚本和 iinstall adobe
WPF XAML
<TextBox x:Name="AdbPath" HorizontalAlignment="Left" Height="24" Margin="131,52,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="116"/>
C#代码
private void BtnInstall_Click(object sender, RoutedEventArgs e)
{
var process = new Process();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = @"C:\Temp\adobe2Rev1.ps1";
process.Start();
process.WaitForExit(); // ...
}
【问题讨论】:
-
powershell 也支持 GUI - 所以你不需要额外的 .NET WPF 应用程序来实现这个 btw
-
您可以以接受路径作为参数的方式创建 powershell 脚本。通过将路径作为 powershell 脚本参数传递来从 wpf 应用程序调用 powershell 脚本
-
WPF
-
private void BtnInstall_Click(object sender, RoutedEventArgs e) { var process = new Process(); process.StartInfo.FileName = "powershell.exe"; process.StartInfo.Arguments = @"C:\Temp\adobe2Rev1.ps1";进程.开始();进程.WaitForExit(); // ... }
-
这是我调用脚本的 wpf 和 C# 代码
标签: c# wpf powershell