I have been racking my head over this for a couple days now and I cannot figure out what is going on. My dev box is a Windows 7 64-bit machine and I am trying to connect via WMI to a Windows Server 2008 domain controller.
My code is pretty simple:
ConnectionOptions options = new ConnectionOptions();
options.Username = _username;
options.Password = _password;
options.EnablePrivileges = true;
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.Default;
ManagementScope scope = new ManagementScope(@"\\" + _hostip + @"\root\cimv2", options);
scope.Connect(); // this works!
ManagementEventWatcher watcher = new ManagementEventWatcher();
watcher.Scope = scope;
watcher.Query = new EventQuery(@"SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' and TargetInstance.LogFile = 'Security'");
watcher.Start() // throws exception
watcher.WaitForNextEvent(); // works
My knowledge of WMI is limited and I cannot figure out why WaitForNextEvent() works but Start() does not. The exception I keep getting is: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I've checked multiple times that the domain controller I'm attempting to connect to is set up properly (remoting is on, enabled and has permission) as is the user account I'm using to connect.
Any ideas and insight would be greatly appreciated.