Eventlog on remote machine

Sorry i get RPC connection exception. Please help.
using System;
using System.Management;
using System.IO;
class App {
[MTAThread]
private static void Main(string[] args)
{
// Beware! the account used to connect must have remote WMI privileges on the remote server.
 
RunProcess M = new RunProcess("c3c3d", "#####", "333");
M.Run();
}
}
sealed class RunProcess
{
private ConnectionOptions co;
private ManagementScope scope;
 
public RunProcess(string ConnectionUser, string ConnectionPassword, string
Machine )
{
co = new ConnectionOptions();
co.Username = ConnectionUser;
co.Password = ConnectionPassword;
co.Impersonation = ImpersonationLevel.Impersonate;
scope = new ManagementScope(@"\\" + Machine + @"\root\cimv2", co);
scope.Connect();
}
public void Run()
{
string logFileName = "SYSTEM";
// default blocksize = 1, larger value may increase network throughput
EnumerationOptions opt = new EnumerationOptions();
opt.BlockSize = 1000;
// Get only Logon/LogOff category from security log
SelectQuery query = new SelectQuery("select CategoryString,TimeGenerated, User, Type from Win32_NtLogEvent where Logfile ='System'");
using(ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query, opt))
{
foreach (ManagementObject mo in searcher.Get()) {
string logInfo = String.Format("{0} - {1} - {2}", mo["Type"],
mo["CategoryString"], mo["User"]);
Console.WriteLine(logInfo);
}
}
}
}

Open in new window

sonu002Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grayeCommented:
I would suspect this is a firewall issue....  On the remote PC, try the following:

netsh firewall set service RemoteAdmin enable
  or
netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sonu002Author Commented:
How do we change this setting please help
0
grayeCommented:
....by typing the commands that I provided
The top one is for WinXP, the bottom for Vista
0
sonu002Author Commented:
Thanks it worked for me!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.