forms - 如何在选择文件窗口上按取消并在 powershell 中重新启动程序
问题描述
我的程序中有一个按钮,可以让用户从他们的计算机中选择一个文件,但是我想这样做,所以当他们按下取消按钮时,它会重新启动整个程序。对此的任何帮助将不胜感激,因为我已经为此苦苦挣扎了一段时间。这是我目前所拥有的......
function SelectDrive($title){
if($global:FirstDrive -eq $null){
$DriveSelection = New-Object System.Windows.Forms.FolderBrowserDialog
$DriveSelection.Description = $title
# $DriveSelection.rootfolder = "MyComputer"
[void]$DriveSelection.ShowDialog()
$global:FirstDrive = $DriveSelection.SelectedPath
}
else{
removeAll
initVal
$FillError.text = ""
$mainForm.controls.AddRange(@($StartUSB,$StartDualMedia,$SelectOne,$USBLabel,$2USBLabel))
$mainForm.refresh()
}
}
解决方案
$ClickedButton = $DriveSelection.ShowDialog()
if ($ClickedButton -eq 'Cancel') {
Start-Process powershell.exe -ArgumentList "-File $($MyInvocation.MyCommand.Definition)"
Exit
}
推荐阅读
- python - 从文件索引字典
- xml - 解析 XML 类型的 Oracle 函数
- angular - 将 localhost:4200 导航到 404 页面
- python - 如何重新安装损坏的 pip?
- php - Laravel - 可重用的资源控制器
- c# - 如何在与 Web API 通信的 ASP.NET Core MVC 应用程序中使用自定义身份验证/授权?
- ios - 在显示的自定义视图中在哪里调用动画
- python - django 异常:未找到带有关键字参数“{'pk':''}' 的“comment_new”的反向
- scala - Spark中自定义对象的RDD问题
- javascript - 在我的网页上加载广告后,航点偏移不再正确