Dar*_*tux 0 powershell user-interface onclick exit winforms
我有一个脚本,可以根据情况使用按钮创建一个小的Windows gui表单;
->单击时,这些按钮将打开远程文件共享上的相应文件;以下是代码;
$run.Add_Click({Invoke-Expression "Powershell \\Fileshare\$Random_File.Doc"}.GetNewClosure())
Run Code Online (Sandbox Code Playgroud)
->我的问题仍然是在单击文件后打开;表格仍然悬挂在背景中;我想知道如何关闭它(如果我也能关闭整个Powershell,那就更好了);我试图将“; exit”嵌入到调用中,但是它给出了错误,还有其他方法吗?
请问我是否需要任何问题或澄清。
我怀疑Invoke-Item \\fileshare\$file
对于要打开的任何文档,运行它都比运行新的PowerShell更好。
要关闭表单,您可以添加$ this.Parent(?)。Close()或仅引用$ form变量-这也应该起作用:
$form = New-Object System.Windows.Forms.Form
$run = New-Object System.Windows.Forms.Button -Property @{
Location = New-Object System.Drawing.Point -Property @{
X = 0
Y = 0
}
Text = 'Run'
}
$run.Add_Click({
Invoke-Item C:\Windows
$form.Close()
})
$form.Controls.Add($run)
$form.ShowDialog()
Run Code Online (Sandbox Code Playgroud)