Eventlog on remote machine

Posted on 2008-11-08
Last Modified: 2013-12-17
Sorry i get RPC connection exception. Please help.
using System;

using System.Management;

using System.IO;

class App {


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");




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);



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"]);






Open in new window

Question by:sonu002
    LVL 41

    Accepted Solution

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

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

    Author Comment

    How do we change this setting please help
    LVL 41

    Assisted Solution

    by:graye typing the commands that I provided
    The top one is for WinXP, the bottom for Vista

    Author Comment

    Thanks it worked for me!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Remote Desktop Shadowing often has a lot of benefits. When helping end users determine problems, it is much easier to see what is going on, what is being slecected and what is being clicked on. While the industry has many products to help with this,…
    How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now