我正在创建一个gui,想要一个弹出窗口让你知道它很忙,但是当它完成特定的任务时关闭它。我唯一能找到的就是…
$popup = New-Object -ComObject wscript.shell
$popup.popup("Running Script, Please Wait....",0,"Running...",0x1)
但问题是,这正在等待响应,然后它将运行脚本。我并不是要求一些人给我写一个脚本,而是一些关于在哪里找到这些信息的指导方针。
我需要powershell弹出一个窗口,然后在运行脚本时将其保留,然后在脚本完成运行时将其关闭。
最好是有另一个windows窗体,运行带有标签的脚本?对于一个简单的任务来说,这似乎是一项过多的工作。但这是动力地狱…
有什么像…
$popup = New-Object -ComObject wscript.shell
$popup.popup("Running Script, Please Wait....",0,"Running...",0x1)
###RUN SCRIPT HERE...
$popup.close()
编辑:::
对于“为什么我要尝试弹出窗口,而不是writeprogress或其他什么东西”…原因是我是在一个gui中做的。不在命令行中。因此,我需要gui基本上通知这个人它很忙,一些任务可能需要6个多小时才能完成,我不希望他们在当前任务运行时到处点击,做其他事情。
编辑2::
由于最初的问题没有得到回答,我将对此保持开放,但我创建了一个包含以下代码的解决方案。
$LabelAlert = New-Object system.windows.forms.label
$LabelAlert.Text = "Working, Please wait."
$LabelAlert.location = New-Object System.Drawing.Point(0,180)
$LabelAlert.width = 590
$LabelAlert.height = 25
$LabelAlert.Visible = $false
$LabelAlert.TextAlign = "TopCenter"
$Form.Controls.Add($LabelAlert)
$FormGroupBox = New-Object System.Windows.Forms.GroupBox
$FormGroupBox.Location = New-Object System.Drawing.Size(0,0)
$FormGroupBox.width = 600
$FormGroupBox.height = 375
$Form.Controls.Add($FormGroupBox)
$startAlert = {
$LabelAlert.Visible = $true
$FormGroupBox.Visible = $false
}
$stopAlert = {
$LabelAlert.Visible = $false
$FormGroupBox.Visible = $true
}
每个表单部分都被移到了分组框中。这个分组框和我的窗口一样大。
每运行一个耗时的脚本
&$startAlert
....script commands go here...
&$stopAlert