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

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
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 ManagementObjectSearcher. But when I tried to use ManagementEventWatcher.Start method I am getting a exception
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I have given the permisions in WMI Control to "rootcimv2" and also given the admin rights to the users account in DCOM Config.
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 I have normal windows application hence I am not using ASP.net(ASPNET user) in my case.
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 My code is-
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 ConnectionOptions connectionOptions = new ConnectionOptions();<br/>
connectionOptions.Username = @"DomainUName";//txtUserName.Text;<br/>
connectionOptions.Password = "pass";//txtPassword.Text;<br/>
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;<br/>
ManagementScope managementScope = new ManagementScope(@" file://\serverrootcimv2",connectionOptions \serverrootcimv2",connectionOptions );<br/>
managementScope.Options.EnablePrivileges = true;<br/>
managementScope.Connect();<br/>
eventWatcher = new ManagementEventWatcher(managementScope, new EventQuery("Select * From __InstanceCreationEvent WHERE TargetInstance ISA Win32_NTLogEvent and TargetInstance.LogFile = Application"));<br/>
eventWatcher.EventArrived += new EventArrivedEventHandler(Arrived);<br/>
eventWatcher.Scope.Options.EnablePrivileges = true;<br/>
eventWatcher.Start();
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 Any help is appriciated
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 Thanks,
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small <span style="color:#000000 Devendra
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small

View the full article
 
Back
Top