Requested registry access is not allowed.

G

Guest

I have a piece of code (written is Visual Studio 2005) that is only reading
the Security EventLog. On Windows XP Professiona/Home this code works just
fine.

int numberOfEntries = myEventLog.Entries.Count;
if (numberOfEntries > 0) ...

However, when run under Windows Vista I get the error "Requested registry
access is not allowed." This error occurs when the first line of code is
executed.

I tried adding the command below before the count is retrieved but it didn't
work.

EventLogPermission elp = new
EventLogPermission(EventLogPermissionAccess.Administrator, ".");

Does anyone know how to get around this issue. This error only occurs with
the Security event log, not the "Application" or "System" event logs.
 
K

Kevin Yu [MSFT]

Hi Steve,

I'm sorry, but Windows Vista development is currently not supported, since
it is only in beta version. Let's wait to see if any community member can
shed some light on this issue.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
C

Chris R. Timmons

I have a piece of code (written is Visual Studio 2005) that is
only reading the Security EventLog. On Windows XP
Professiona/Home this code works just fine.

int numberOfEntries = myEventLog.Entries.Count;
if (numberOfEntries > 0) ...

However, when run under Windows Vista I get the error "Requested
registry access is not allowed." This error occurs when the
first line of code is executed.

I tried adding the command below before the count is retrieved
but it didn't work.

EventLogPermission elp = new
EventLogPermission(EventLogPermissionAccess.Administrator, ".");

Steve,

I don't have Windows Vista, but .Net Code Access Security (CAS) can
be a little frustrating when it's first encountered.

Creating a permission object does not have the effect of granting
the program that permission. A .Net program is subject to the
combination of permissions allowed by the OS for the user account the
program is running under, and the permissions allowed by the .Net
runtime (go to the Control Panel/Administrative Tools and open the MS
..Net Configuration utility).

See "Code Access Security" on MSDN2 for more info:

http://msdn2.microsoft.com/en-us/library/930b76w0(VS.80).aspx
Does anyone know how to get around this issue. This error only
occurs with the Security event log, not the "Application" or
"System" event logs.

If the program is not being run from your machine (i.e. it's being
run from a network drive), then .Net will not give that program a
full set of permissions.

If it's being run on your machine, check the permissions of the user
account the program is running under.

Finally, as Kevin Yu alluded to, Vista is still in beta. It's
possible this is just a yet-to-be-fixed quirk of that OS.
 
W

Willy Denoyette [MVP]

|I have a piece of code (written is Visual Studio 2005) that is only reading
| the Security EventLog. On Windows XP Professiona/Home this code works
just
| fine.
|
| int numberOfEntries = myEventLog.Entries.Count;
| if (numberOfEntries > 0) ...
|
| However, when run under Windows Vista I get the error "Requested registry
| access is not allowed." This error occurs when the first line of code is
| executed.
|
| I tried adding the command below before the count is retrieved but it
didn't
| work.
|
| EventLogPermission elp = new
| EventLogPermission(EventLogPermissionAccess.Administrator, ".");
|
| Does anyone know how to get around this issue. This error only occurs
with
| the Security event log, not the "Application" or "System" event logs.
|
| --
| -----------
| Thanks,
| Steve

Because of User Account Control (UAC) in Vista, the application requires
elevated permissions to get at the Security data. Please read this:
http://msdn.microsoft.com/windowsvi...l=/library/en-us/dnlong/html/accprotvista.asp,
especially the part that talks about an assembly manifest.

Note also that you should post Vista related questions to the Microsoft
forums at http://forums.microsoft.com

Willy.
 
G

Guest

How does one go about configuring a C# appliation to run with Admin
privileges? My test tool is installed under the adminitstrator login and
runs in that environment.

I don't understand what needs to be done to do this.

This line of code (reading the number of Security EventLog entries) is the
only line (out of 1000's) that will not run under Vista. I find it
frustrating.
 
W

Willy Denoyette [MVP]

Please move this to the Vista forums, this issue is not C# or .NET related,
it's about the way security is implemented in Vista.
http://msdn.microsoft.com/windowsvi...l=/library/en-us/dnlong/html/accprotvista.asp,
explain exactly what should be done to run with elevated privileges.
Note that by default the Administrator account is disabled in Vista, you
aren't running with administrator privileges, even if you are a member of
administrators!. I would suggest you read as much as you can about the new
security model before you start coding, also keep in mind that Vista is
still in beta, nothing is carved in stone yet and many things might change
before RTM.

Willy.

| How does one go about configuring a C# appliation to run with Admin
| privileges? My test tool is installed under the adminitstrator login and
| runs in that environment.
|
| I don't understand what needs to be done to do this.
|
| This line of code (reading the number of Security EventLog entries) is the
| only line (out of 1000's) that will not run under Vista. I find it
| frustrating.
| --
| -----------
| Thanks,
| Steve
|
|
| "Willy Denoyette [MVP]" wrote:
|
| >
| > | > |I have a piece of code (written is Visual Studio 2005) that is only
reading
| > | the Security EventLog. On Windows XP Professiona/Home this code works
| > just
| > | fine.
| > |
| > | int numberOfEntries = myEventLog.Entries.Count;
| > | if (numberOfEntries > 0) ...
| > |
| > | However, when run under Windows Vista I get the error "Requested
registry
| > | access is not allowed." This error occurs when the first line of code
is
| > | executed.
| > |
| > | I tried adding the command below before the count is retrieved but it
| > didn't
| > | work.
| > |
| > | EventLogPermission elp = new
| > | EventLogPermission(EventLogPermissionAccess.Administrator, ".");
| > |
| > | Does anyone know how to get around this issue. This error only occurs
| > with
| > | the Security event log, not the "Application" or "System" event logs.
| > |
| > | --
| > | -----------
| > | Thanks,
| > | Steve
| >
| > Because of User Account Control (UAC) in Vista, the application requires
| > elevated permissions to get at the Security data. Please read this:
| >
http://msdn.microsoft.com/windowsvi...l=/library/en-us/dnlong/html/accprotvista.asp,
| > especially the part that talks about an assembly manifest.
| >
| > Note also that you should post Vista related questions to the Microsoft
| > forums at http://forums.microsoft.com
| >
| > Willy.
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top