[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$folder = "E:\test" #要监控的文件夹
#设置任务栏图标
$Icon = "C:\Windows\winsxs\amd64_microsoft-windows-dxp-deviceexperience_31bf3856ad364e35_6.1.7601.17514_none_a54b31331066c8e2\sync.ico"
$form = new-object System.Windows.Forms.Form
$ni = new-object System.Windows.Forms.NotifyIcon
$niMenu = new-object System.Windows.Forms.ContextMenu
$watcher = New-Object System.IO.FileSystemWatcher $folder
$ni.Icon = New-object System.Drawing.Icon($Icon)
$ni.ContextMenu = $niMenu
$miExit = new-object System.Windows.Forms.MenuItem
$miExit.Text = "Exit"
$miExit.Add_Click({Stop-Process -id $pid})
$niMenu.MenuItems.AddRange(@($miExit))
$watcher.Filter="*.*"
$watcher.InternalBufferSize=65536
$watcher.IncludeSubDirectories = $true
$watcher.SynchronizingObject = $form
$form.ShowInTaskbar = $False
$
powershell FileSystemWatcher监控文件变化
最新推荐文章于 2025-02-14 19:40:39 发布