Tag: managementeventwatcher

ManagementEventWatcher(WMI)从远程计算机通知事件时发生exception

我正在尝试使用WMI和C#从远程计算机的事件查看器获取通知。 我可以使用ManagementObjectSearcher连接系统并获取事件日志。 但是当我尝试使用ManagementEventWatcher.Start方法时,我得到一个exception: 访问被拒绝。 (来自HRESULT的exception:0x80070005(E_ACCESSDENIED)) 我已将WMI Control中的root\cimv2赋予root\cimv2并在DCOM Config中授予用户帐户的管理员权限。 我有正常的Windows应用程序,因此我不使用ASP.net(ASPNET用户)在我的情况下。 我的代码是: ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.Username = @”Domain\UName”;//txtUserName.Text; connectionOptions.Password = “pass”;//txtPassword.Text; connectionOptions.Impersonation = ImpersonationLevel.Impersonate; ManagementScope managementScope = new ManagementScope(@”\\server\root\cimv2″,connectionOptions); managementScope.Options.EnablePrivileges = true; managementScope.Connect(); // this line is executing fine. eventWatcher = new ManagementEventWatcher(managementScope, new EventQuery(“Select * From __InstanceCreationEvent WHERE TargetInstance ISA ‘Win32_NTLogEvent’ and TargetInstance.LogFile = […]