当最小化时显示powershell消息框

当最小化时显示powershell消息框

问题描述:

我有一个监视我的文件系统的PowerShell脚本。我希望它在某个文件夹中检测到新文件时显示一个消息框。当最小化时显示powershell消息框

但是,因为我的PowerShell脚本运行最小化,消息框不会按预期方式弹出。

有没有办法让消息框出现在所有其他窗口的顶部,最好是选定的,而不会使PowerShell脚本最小化?

我生成这个代码的消息框(虽然任何类型的屏幕上的通知,将是一件好事)

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO 
    $watcher = New-Object System.IO.FileSystemWatcher 
    $watcher.Path= "C:\Users\[...]" 
    $watcher.Filter = "*.bin" 
    $watcher.IncludeSubdirectories = $true 
    $watcher.EnableRaisingEvents = $true 
    Add-Type -AssemblyName PresentationFramework #reference for message box 
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED 
    $action = { [System.Windows.MessageBox]::Show('Binary received') #display msgbox 
       }  
### DECIDE WHICH EVENTS SHOULD BE WATCHED 
    Register-ObjectEvent $watcher "Created" -Action $action 
    while ($true) {sleep 5} 

要显示一个消息框作为一个始终在最前面的对话框,您可以使用ServiceNotification风格使用MessageBox.Show对话框:

Add-Type -AssemblyName System.Windows.Forms 

[System.Windows.Forms.MessageBox]::Show("Message","Title",` 
    [System.Windows.Forms.MessageBoxButtons]::OK,` 
    [System.Windows.Forms.MessageBoxIcon]::Information,` 
    [System.Windows.Forms.MessageBoxDefaultButton]::Button1,` 
    [System.Windows.Forms.MessageBoxOptions]::ServiceNotification)