[quoted text, click to view] "calderara" <calderara@discussions.microsoft.com> wrote in message
news:F0AB32EE-4BE9-43A6-AFD2-B2ABEEDA08D2@microsoft.com...
> Dear all,
>
> I am buidling as assembly which logs potentials generated error or
> exception
> in Event viewer.
> For that I am through code creating an EventSource for the log before
> writing inside.
> I have noticed that for creating that source you need to be an
> administrator
> user.
> So if my libryr is executed my a client aplication under a normal user
> context, I will have an exception error when creating the EventSource.
>
> How can I be an administrator from my code only during the needed time ?
> Sure I might change the contect of my code to be an admin and then
> impersonate during the execution of my admin part, then probably use the
> Undo
> method to recover to normal user but how ?
You won't be able to do this unless the user knows administrative account
credentials. A better approach would be to register the event log source
during the installation of the application, which is presumably performed
under an administrative user context.
[quoted text, click to view] > My assembly would need also the EvenLog permission i guess ?
To write to a previously registered event log source,
EventLogPermission\Write for the target event log (presumably the local
machine event log in this case). Locally installed code is granted this
permission under default CAS policy.
[quoted text, click to view] > As declarative of imperative mode.
Sorry, but I don't understand what you mean by this.
[quoted text, click to view] >
> thnaks for help
> regards
> serge