DukeOfMarmalade
DukeOfMarmalade

Reputation: 2788

Grant my code Event Log permissions

Hi I am trying to grant my application full access to the event logs, so I have put this code in, and I am basicallyjust wondering if somebody who has used/seen this before can verify that what I have done is correct, or am I missing any steps?

        string thisMachineName = System.Net.Dns.GetHostName();

        EventLogPermission eventReaderPermission = new EventLogPermission(EventLogPermissionAccess.Administer, thisMachineName);
        eventReaderPermission.Demand();

Upvotes: 2

Views: 950

Answers (1)

dgvid
dgvid

Reputation: 26633

The Demand() method will throw a security exception at run time if your application does not already have Administer-level access to the event log. It will not grant permission.

Granting access is much more difficult than a single method call, I'm afraid. You should read-up on how to manage code access security.

Upvotes: 1

Related Questions