Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文件移动时Powershell弹出窗口_Powershell_Popup - Fatal编程技术网

文件移动时Powershell弹出窗口

文件移动时Powershell弹出窗口,powershell,popup,Powershell,Popup,当我的脚本启动时,它会将文件从一个目录移动到另一个目录。文件完全下载后,我启动一个应用程序。 这一切工作,但我想是一个弹出窗口出现,而文件正在被移动(大文件) 当我调试代码时,一旦它点击Move-Item Cmdlet,它将等待该命令完成后再继续。我要做的是,当Move-Item Cmdlet运行时,弹出一个信息窗口。 我知道如何做弹出和移动项目,我只是不知道如何让它的工作方式,我想要的。有什么想法吗? 弹出代码 #pop up window letting mechanic know we

当我的脚本启动时,它会将文件从一个目录移动到另一个目录。文件完全下载后,我启动一个应用程序。
这一切工作,但我想是一个弹出窗口出现,而文件正在被移动(大文件)
当我调试代码时,一旦它点击Move-Item Cmdlet,它将等待该命令完成后再继续。我要做的是,当Move-Item Cmdlet运行时,弹出一个信息窗口。 我知道如何做弹出和移动项目,我只是不知道如何让它的工作方式,我想要的。有什么想法吗?

弹出代码

 #pop up window letting mechanic know we are waiting for the files to be downloaded before opeing the SMT application
            $wshell = New-Object -ComObject Wscript.Shell
            $wshell.Popup("The EAFR file is still being moved to the correct directory, please wait.",0,"SMT Status",0)

#Move-Item
    $MLMoveDir = "C:\move\data\AutoUpload\"
    Move-Item -LiteralPath ($filePath) $MLMoveDir

因此,您可以做的是将移动项作为作业启动,然后执行一段时间((获取作业“jobname”).state-ne completed){do popup}。我看起来像这样:

#Move-Item
    $MLMoveDir = "C:\move\data\AutoUpload\"
    $MoveJob = Start-Job -scriptblock {Move-Item -LiteralPath ($filePath) $MLMoveDir}
#Show Popup
    While($movejob.state -ne "Completed"){
        $wshell = New-Object -ComObject Wscript.Shell
        $wshell.Popup("The EAFR file is still being moved to the correct directory, please wait.",1,"SMT Status",0)
    }

这样,弹出窗口显示1秒,如果移动仍在进行,则再次显示。我不知道它甚至会消失/重新显示,因此它可能是无缝的。

一个选项是使用WinForms显示“请等待”对话框,而不是用户必须关闭的弹出窗口。比如:

Add-Type -AssemblyName System.Windows.Forms 
$Form = New-Object system.Windows.Forms.Form
$Label = New-Object System.Windows.Forms.Label
$Form.Controls.Add($Label)
$Label.Text = "Copying file, please wait."
$Label.AutoSize = $True
$Form.Visible = $True
$Form.Update()

#Move-Item
$MLMoveDir = "C:\move\data\AutoUpload\"
Move-Item -LiteralPath ($filePath) $MLMoveDir

#Hide popup
$Form.Close()

为什么要弹出窗口?为什么不直接写入控制台,然后在完成后再写入?因为用户正在单击图标以启动应用程序,而不是PowerShell。不清楚如何让它以我想要的方式工作。你希望它以什么方式工作?他希望在移动文件时保持弹出窗口在屏幕上。问题是我不知道在移动完成后如何关闭弹出窗口。我可以建议弹出窗口的方法,并使弹出窗口在作业移动过程中不断出现,但让它消失却让我一时想不起来。我记得wscript.popup内置了一个超时,只是必须利用它。我喜欢这个@TheMadTechnician,我只需要看看是否可以在将要运行此功能的机器上升级到PowerShell 3.0。