Exception while ManagementEventWatcher(WMI) to notify events from remote machine

后端 未结 3 1036
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 07:39

I am trying to get notification from a remote machine \'s event viewer using WMI and C#. I am able to connect the system and also get event log by using ManagementObje

3条回答
  •  情歌与酒
    2021-01-06 08:36

    Try listening semi-synchronously with WaitForNextEvent():

        var managementScope = new ManagementScope(@"\\mysever\root\onguard"); 
        managementScope.Connect(); 
    
        var query = new EventQuery("select * from lnl_AccessEvent");
        var eventWatcher = new ManagementEventWatcher(managementScope, query);
        var wmiEvent = eventWatcher.WaitForNextEvent();
        Console.Out.WriteLine(wmiEvent.GetPropertyValue("Description"));
    

    We've also found wbemtest.exe useful. Click the Notification Query... button to listen for events. You can try the various connection methods (synchronous, asynchronous or semi-synchorous). All connection methods work when connecting to your local machine but we were only able to get semi-synchronous to work remotely. Asynchronous (which you are using) is more complex (and less secure) because the server must make a connection back to the client.

    Some good information here on security and configuration settings: http://www.packettrap.com/network/Knowledge-Base/PacketTrap-MSP/WMI-Troubleshooting.aspx#_Toc239699682

提交回复
热议问题