1

PowerShell の FileSystemWatcher コマンドレットを使用すると、System32 または Windows 7 コンピューターのサブフォルダーを監視していないように見えることに気付きました。My Documents のサブフォルダーを監視するときに問題なく動作するスクリプトがあります (つまり、"C:\Users\W\Documents\Fichiers PowerShell" は機能する fplder パスです)。 System32 (つまり、C:\Windows\System32\Recovery は機能しないパスです)

これは私が使用しているスクリプトですが、System32 パスは他の FileSystemWatcher スクリプトでは機能していません。回避策についてアドバイスをいただければ幸いです。C:\Windows\System32\Recovery を監視する必要があります。ありがとうございました。

function FileSystemWatcher([string]$log = "C:\Users\W\Documents\Fichiers     PowerShell\newfiles.txt",
[string]$folder = "C:\Windows\System32\Recovery",
[string]$filter  = "*ps1",
[char]$timeout = 1000
){
$FileSystemWatcher = New-object System.IO.FileSystemWatcher $folder, $filter

Write-Host "Press any key to abort monitoring $folder"
do {

$result = $FileSystemWatcher.WaitForChanged("created", $timeout)

if ($result.TimedOut -eq $false) {
$result.Name |
  Out-File $log -Append 
Write-Warning ("Detected new file: " + $result.name)
 $filename = (gc $log -ea 0)



ii "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" 
remove-item "C:\Users\W\Documents\Fichiers PowerShell\newfiles.txt"


} 
} until ( [System.Console]::KeyAvailable )

Write-Host "Monitoring aborted."
Invoke-Item $log}



FileSystemWatcher
4

1 に答える 1

1

これを試してください:

$fsw = New-Object System.IO.FileSystemWatcher C:\Windows\System32 -Property @{
    IncludeSubdirectories = $true              
    NotifyFilter = [System.IO.NotifyFilters]::DirectoryName
}

$event = Register-ObjectEvent $fsw Created -SourceIdentifier DirectoryCreated -Action { 
    Write-Host "$($event.SourceArgs | fl * | Out-String)"
}

md C:\Windows\System32\temp2
于 2012-09-12T12:41:49.453 に答える