Register-ObjectEvent查找所需參數中的對象實例InputObject。什麼是對象的靜態語法(共享)事件?在PowerShell中訂閱對象的靜態事件的語法是什麼?
UPDATE:正確的語法TimeChanged:
$systemEvents = [Microsoft.Win32.SystemEvents]
$timeChanged = Register-ObjectEvent -InputObject $systemEvents
-EventName 'TimeChanged' -Action { Write-Host "Time changed" }
不幸的是,SystemEvents不會在PowerShell ISE中信號。下面是使用對象的staic事件作品無處不在的樣本:
$networkInformation = [System.Net.NetworkInformation.NetworkChange];
$networkAddressChanged = Register-ObjectEvent -InputObject $networkInformation
-EventName 'NetworkAddressChanged'
-Action { Write-Host "NetworkAddressChanged event signaled" }
在PowerShell中有一個消息循環運行,但您需要以管理員身份運行才能訪問它。 – 2010-03-02 02:08:55