Test.PS1- $dstDir = 'E:\Test'; #待监视的目录
- $timeout = 120; #超时时间 120 秒
- $watcher = New-Object System.IO.FileSystemWatcher($dstDir);
- $watcher.IncludeSubdirectories = $true;
-
- while(1) {
- Unregister-Event -SourceIdentifier 'MyFileWatcher' -ErrorAction SilentlyContinue;
- Remove-Event -SourceIdentifier 'MyFileWatcher' -ErrorAction SilentlyContinue;
- Register-ObjectEvent -Input $watcher -EventName Created -SourceIdentifier 'MyFileWatcher';
- $event = Wait-Event -SourceIdentifier 'MyFileWatcher' -Timeout $timeout;
- $file = $event.SourceEventArgs.FullPath;
- if($file -eq $null) {
- &'C:\Program Files\Internet Explorer\iexplore.exe' #超时后运行其它程序
- break; #退出监控
- }
- }
复制代码
|