msnews.microsoft.com
2004-12-03 04:52:14 UTC
Having issues getting any remote events working.
I have tried numerous example code and all of them are getting Access
Denied.
Can someone provide a tested example that works.
I am running WinXPSP2, windows firewall is turned off.
Remote Server is Win2003
WBEMTEST works fine to the same remote machine when using semisynchronous.
I am trying to get the same event working in a C# Console App and getting
Access Denied.
I have notice in the Security Log on the remote machine that when I connect
with the C# app it will try on Logon to the remote machine using my local
user account aswell as the Impersonated User.
It is the local user that does not exist on the Remote Machine and is
Failing.
I am successfully polling Statistics through WMI to the same machine, It is
only when I try to use the ManagementEventWatcher.Start() it gets Access
Denied.
I am trying to do a semisychronous method in C#
Any examples out there.
All examples I have seen are to localhost
Here is one of the lastest examples I am trying.
public class WMIEventLogWatcher
{
EventLogHandler _handler = null;
ManagementEventWatcher _watcher = null;
public WMIEventLogWatcher(string host,string user,string pass)
{
// Although connection information is not used in this example, I'll show
you how to construct it here
//Connection credentials to the remote computer - not needed if the logged
in account has access
ConnectionOptions co = new ConnectionOptions();
co.Username = user;
co.Password = pass;
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.Packet;
co.Timeout = new TimeSpan(0,0,0,10);
// Connect to the remote machine's WMI repository
ManagementScope scp = new ManagementScope(@"\\"+host+@"\root\cimv2",co);
// connect it
scp.Connect();
Console.WriteLine("Connected.");
// construct the watcher object from the scope and the query
_watcher = new ManagementEventWatcher(scp,
new EventQuery("SELECT * FROM __InstanceCreationEvent WHERE TargetInstance
ISA 'Win32_NTLogEvent'"));
// connect an event handler to the event returned when the event log changed
_handler = new EventLogHandler ();
_watcher.EventArrived += new EventArrivedEventHandler(_handler.Arrived);
}
public void Start()
{
//Start watching for events
try
{
_watcher.Start();
Console.WriteLine("Started...");
}
catch(Exception e)
{
Console.WriteLine("WatcherFailed:"+e.Message);
}
}
public class EventLogHandler
{
public void Arrived(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Event Log Changed = ");
// Get the Event object and display it
PropertyData pd;
if( ( pd = e.NewEvent.Properties["TargetInstance"] ) != null )
{
ManagementBaseObject mbo = pd.Value as ManagementBaseObject;
if( mbo.Properties["Message"].Value != null )
{
Console.WriteLine( mbo.Properties["Message"].Value );
}
}
}
}
}
Thanks
Shayne
I have tried numerous example code and all of them are getting Access
Denied.
Can someone provide a tested example that works.
I am running WinXPSP2, windows firewall is turned off.
Remote Server is Win2003
WBEMTEST works fine to the same remote machine when using semisynchronous.
I am trying to get the same event working in a C# Console App and getting
Access Denied.
I have notice in the Security Log on the remote machine that when I connect
with the C# app it will try on Logon to the remote machine using my local
user account aswell as the Impersonated User.
It is the local user that does not exist on the Remote Machine and is
Failing.
I am successfully polling Statistics through WMI to the same machine, It is
only when I try to use the ManagementEventWatcher.Start() it gets Access
Denied.
I am trying to do a semisychronous method in C#
Any examples out there.
All examples I have seen are to localhost
Here is one of the lastest examples I am trying.
public class WMIEventLogWatcher
{
EventLogHandler _handler = null;
ManagementEventWatcher _watcher = null;
public WMIEventLogWatcher(string host,string user,string pass)
{
// Although connection information is not used in this example, I'll show
you how to construct it here
//Connection credentials to the remote computer - not needed if the logged
in account has access
ConnectionOptions co = new ConnectionOptions();
co.Username = user;
co.Password = pass;
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.Packet;
co.Timeout = new TimeSpan(0,0,0,10);
// Connect to the remote machine's WMI repository
ManagementScope scp = new ManagementScope(@"\\"+host+@"\root\cimv2",co);
// connect it
scp.Connect();
Console.WriteLine("Connected.");
// construct the watcher object from the scope and the query
_watcher = new ManagementEventWatcher(scp,
new EventQuery("SELECT * FROM __InstanceCreationEvent WHERE TargetInstance
ISA 'Win32_NTLogEvent'"));
// connect an event handler to the event returned when the event log changed
_handler = new EventLogHandler ();
_watcher.EventArrived += new EventArrivedEventHandler(_handler.Arrived);
}
public void Start()
{
//Start watching for events
try
{
_watcher.Start();
Console.WriteLine("Started...");
}
catch(Exception e)
{
Console.WriteLine("WatcherFailed:"+e.Message);
}
}
public class EventLogHandler
{
public void Arrived(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Event Log Changed = ");
// Get the Event object and display it
PropertyData pd;
if( ( pd = e.NewEvent.Properties["TargetInstance"] ) != null )
{
ManagementBaseObject mbo = pd.Value as ManagementBaseObject;
if( mbo.Properties["Message"].Value != null )
{
Console.WriteLine( mbo.Properties["Message"].Value );
}
}
}
}
}
Thanks
Shayne