Link to home
Start Free TrialLog in
Avatar of sonu002
sonu002

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sonu002
sonu002

ASKER

How do we change this setting please help
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sonu002

ASKER

Thanks it worked for me!!!